Skip to content

Commit

Permalink
Refactor : virer le workspace / racourcicement des nom de socket
Browse files Browse the repository at this point in the history
  • Loading branch information
sl4shme committed Oct 8, 2013
1 parent b3a6453 commit 195049c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
#Need aussi de revoir le system de gestion des nick id
#retrouver le __del__
#Gerer la longueur de l'historique
#Pb de prompt qui disparait
#switch channel
#Ne pas afficher les message si inscroll
#motbye
#bug avec le /help quand les autres parles en fond
#limiter la longeur des pseudos
1 change: 1 addition & 0 deletions bugReport
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[15:28] TaMereEnStringCestAnonyme : ne pas afficher les fails de commandes qui commence avec un /
26 changes: 13 additions & 13 deletions minion.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import socket, os, re, hashlib, threading

class SocketManager(threading.Thread):
def __init__(self, pid, name, hash, scr):
def __init__(self, pid, channel, hash, scr):
threading.Thread.__init__(self)
self.screen=scr
self.workspace=name
self.hash=hash
self.address='\0sschat|'+pid+'|'+self.hash
self.channel=channel
self.channelHash=hash
self.address='\0'+pid+'|'+self.channelHash
self.initPeers()
self.mySock=socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.mySock.bind(self.address)
Expand All @@ -28,14 +28,14 @@ def handlerGetComm(self, incMess):
def handlerAddPeer(self, mess):
pid, name = mess.split("|")
self.peers.append(pid)
self.screen.setTitle(self.workspace, len(self.peers))
self.screen.setTitle(self.channel, len(self.peers))
self.screen.printMessage(name+"("+pid+") joined.")

def handlerRemPeer(self, mess):
pid, name, reason = mess.split("|")
try:
self.peers.remove(pid)
self.screen.setTitle(self.workspace, len(self.peers))
self.screen.setTitle(self.channel, len(self.peers))
self.screen.printMessage(name+"("+pid+") leaved. (Reason:"+reason+")")
except: #This doesn't belong here
self.screen.printMessage("message not delivered!")
Expand All @@ -46,32 +46,32 @@ def handlerGetMess(self, message):
def initPeers(self):
#je preferrerais aller les demander a un random peer
self.peers=[]
expr = re.compile(r'.*%s.*' % self.hash)
expr = re.compile(r'.*%s.*' % self.channelHash)
for line in open("/proc/net/unix"):
match = expr.search(line)
if match:
matchLine = match.group()
matchLine = matchLine.split("@", 1)
matchLine = matchLine[1]
matchLine = matchLine.split("|", 3)
self.peers.append(matchLine[1])
self.peers.append(matchLine[0])


class Minion:
def __init__(self, workspaceName, scr, nickname):
def __init__(self, channel, scr, nickname):
self.pid=str(os.getpid())
self.workspace=workspaceName
self.hashWorkspace=hashlib.sha256(self.workspace).hexdigest()
self.channel=channel
self.channelHash=hashlib.sha256(self.channel).hexdigest()
self.nickname=nickname
self.mySocket=SocketManager(self.pid,self.workspace, self.hashWorkspace, scr)
self.mySocket=SocketManager(self.pid,self.channel, self.channelHash, scr)
self.mySocket.setDaemon(True)
self.mySocket.start()
message="/add "+self.pid+"|"+nickname
self.sendMessage(message)

def sendMessageTo(self, outMessage, peerPid, failed=0):
peerSock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
peerAddress = '\0sschat|'+str(peerPid)+'|'+self.hashWorkspace
peerAddress = '\0'+str(peerPid)+'|'+self.channelHash
try :
peerSock.sendto(outMessage, peerAddress)
except :
Expand Down

0 comments on commit 195049c

Please sign in to comment.