Jump to content
fedorffixxzz

[Py] cmiN's chat.py - adaptat

Recommended Posts

Se pare ca s-a uitat de tot de acest proiect foarte interesant. Am patchuit script-ul original realizand urmatorul changelog:

  • fix client ^C, va trimite KILLME catre server acesta fiind sters din lista, de asemenea client-ul face SIGTERM
  • fix server ^C, uneori ramanea blocat dupa ce afisa "[!] Forcibly closed." probabil in timpul incercarii log.close()
  • introdus /KILLME in client, daca aceasta comanda este executata va fi anulat de server si nerecunoscut
  • implementare server-side setsockopt pentru tuning-ul socket-urilor ce raman in stadiul TIME_WAIT, vezi: http://unixguide.net/network/socketfaq/4.5.shtml
  • fix pentru KILLME, inainte conexiunea nu era cu adeverat inchisa, se foloseste acum SHUT_RDWR si .close()

TODO:

  • de testat comanda/comportamentul cu mai multi clienti -> server
  • altele?

DONE:

  • de rectificat in client si server segterm-ul: try pe subprocess.Popen, la exceptie sa se faca .communicate() si conditiile pentru returncode etc. (prea tarziu acum)
  • de testat daca la /KILLME clientul si conexiunea sa sunt flushed (nu ocupa socket cu server-ul aiurea => "self" DoS?), nu facea flush, odata la interrupt vedem ca ramanea conexiunea in FIN_WAIT, in acest moment clientul putea realiza o alta conexiune, intr-adevar, reinitializa socket-ul ce era pe FIN_WAIT insa nu este recomandat:
    $ netstat -antpul | grep 51337
    tcp 0 0 127.0.1.1:51337 0.0.0.0:* LISTEN 12983/python
    tcp 0 0 127.0.0.1:38536 127.0.1.1:51337 [b][color=red]FIN_WAIT2[/color][/b] -
    tcp 1 0 127.0.1.1:51337 127.0.0.1:38536 CLOSE_WAIT

    acum insa, este inchisa, ramane in TIME_WAIT insa nu pentru mult timp

  • fix linia 434, trebuie identare la
    log.write("\n[!] Errors encountered.\n\n", MSGTOEXIT) sa cada sub if (prea tarziu acum)

chat.py original:

http://codepad.org/r9FCqTyC

chat.py patches (old):


patch0.1 :: http://codepad.org/Q6uJNAbH

current chat.py patched (0.2):

http://codepad.org/6mCZ9DO6

diferenta (patch 0.1 - patch 0.2):

http://pastie.org/private/0cthpd9lbvlbikmjfkqr7a

Critici constructive?

Edited by fedorffixxzz
update patch 0.2
  • Upvote 1
Link to comment
Share on other sites

De fapt o solutie complet buna este socket-ul sa fie non blocking atunci cand un client face interrupt.

nu stiu daca este acoperita complet in ultimul patch, teoretic ar trebui. probabil un test unde client-ul nu are patch de a trimite /kill ar raspunde la intrebare... cine doreste sa faca testul si are timp e binevenit

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...