def setUpPostSession(self): """ override TestAsServer """ TestAsServer.setUpPostSession(self) self.mypermid = str(self.my_keypair.pub().get_der()) self.hispermid = str(self.his_keypair.pub().get_der()) # Calculating the infohash for proxyservice.test.torrent self.torrentfile = os.path.join('extend_hs_dir','proxyservice.test.torrent') # Read torrentfile to calculate the infohash torrentfile_content = open(self.torrentfile, "rb") # Decode all the file metainfo = bdecode(torrentfile_content.read()) # Re-encode only the info section self.infohash = hashlib.sha1(bencode(metainfo['info'])).digest() # Close the torrentfile torrentfile_content.close() # Add us as friend, so he will accept the ASK_FOR_HELP if False: # TEMP friendsdb = FriendDBHandler.getInstance() friendsdb.addFriend(self.mypermid) else: self.session.set_overlay_request_policy(AllowAllRequestPolicy()) self.session.set_download_states_callback(self.states_callback)
def setUpPostSession(self): """ override TestAsServer """ TestAsServer.setUpPostSession(self) self.mypermid = str(self.my_keypair.pub().get_der()) self.hispermid = str(self.his_keypair.pub().get_der()) # Calculating the infohash for proxyservice.test.torrent self.torrentfile = os.path.join('extend_hs_dir', 'proxyservice.test.torrent') # Read torrentfile to calculate the infohash torrentfile_content = open(self.torrentfile, "rb") # Decode all the file metainfo = bdecode(torrentfile_content.read()) # Re-encode only the info section self.infohash = hashlib.sha1(bencode(metainfo['info'])).digest() # Close the torrentfile torrentfile_content.close() # Add us as friend, so he will accept the ASK_FOR_HELP if False: # TEMP friendsdb = FriendDBHandler.getInstance() friendsdb.addFriend(self.mypermid) else: self.session.set_overlay_request_policy(AllowAllRequestPolicy()) self.session.set_download_states_callback(self.states_callback)
def __init__(self): if FriendshipMsgHandler.__singleton: raise RuntimeError, "FriendshipMsgHandler is singleton" self.overlay_bridge = None self.currmsgs = {} self.online_fsext_peers = Set() # online peers that speak FRIENDSHIP ext self.peerdb = PeerDBHandler.getInstance() self.frienddb = FriendDBHandler.getInstance() self.friendshipStatistics_db = FriendshipStatisticsDBHandler.getInstance() self.list_no_of_conn_attempts_per_target= {} self.usercallback = None
def __init__(self, parent, utility, frame): self.utility = utility self.frame = frame style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER pos = wx.DefaultPosition size = wx.Size(530, 420) #size, split = self.getWindowSettings() title = self.utility.lang.get('managefriends') wx.Panel.__init__(self, parent, -1) # 1. Read friends from DB, and figure out who's already helping # for this torrent self.friendsdb = FriendDBHandler.getInstance() # 2. Build GUI mainbox = wx.BoxSizer(wx.VERTICAL) # 3. Friends in top window #friendsbox_title = wx.StaticBox(self, -1, self.utility.lang.get('friends')) friendsbox = wx.BoxSizer(wx.VERTICAL) self.friendListCtrl = FriendList(self, self.friendsdb) friendsbox.Add(self.friendListCtrl, 1, wx.EXPAND | wx.TOP, 5) # 4. Buttons in lower window botbox = wx.BoxSizer(wx.HORIZONTAL) button = wx.Button(self, -1, self.utility.lang.get('buttons_add'), style=wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.addFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) button = wx.Button(self, -1, self.utility.lang.get('buttons_edit'), style=wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.editFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) button = wx.Button(self, -1, self.utility.lang.get('buttons_remove'), style=wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.removeFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) # 5. Show GUI mainbox.Add(friendsbox, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 5) mainbox.Add(botbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5) self.SetSizerAndFit(mainbox)
def setUpPostSession(self): """ override TestAsServer """ TestAsServer.setUpPostSession(self) self.mypermid = str(self.my_keypair.pub().get_der()) self.hispermid = str(self.his_keypair.pub().get_der()) # This is the infohash of the torrent in test/extend_hs_dir self.infohash = '\xccg\x07\xe2\x9e!]\x16\xae{\xb8\x10?\xf9\xa5\xf9\x07\xfdBk' self.torrentfile = os.path.join('extend_hs_dir','dummydata.merkle.torrent') # Add us as friend, so he will accept the DOWNLOAD_HELP if False: # TEMP friendsdb = FriendDBHandler.getInstance() friendsdb.addFriend(self.mypermid) else: self.session.set_overlay_request_policy(AllowAllRequestPolicy())
def setUpPostSession(self): """ override TestAsServer """ TestAsServer.setUpPostSession(self) self.mypermid = str(self.my_keypair.pub().get_der()) self.hispermid = str(self.his_keypair.pub().get_der()) # This is the infohash of the torrent in test/extend_hs_dir self.infohash = '\xccg\x07\xe2\x9e!]\x16\xae{\xb8\x10?\xf9\xa5\xf9\x07\xfdBk' self.torrentfile = os.path.join('extend_hs_dir', 'dummydata.merkle.torrent') # Add us as friend, so he will accept the DOWNLOAD_HELP if False: # TEMP friendsdb = FriendDBHandler.getInstance() friendsdb.addFriend(self.mypermid) else: self.session.set_overlay_request_policy(AllowAllRequestPolicy())
def __init__(self, parent, utility, frame): self.utility = utility self.frame = frame style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER pos = wx.DefaultPosition size = wx.Size(530, 420) #size, split = self.getWindowSettings() title = self.utility.lang.get('managefriends') wx.Panel.__init__(self, parent, -1) # 1. Read friends from DB, and figure out who's already helping # for this torrent self.friendsdb = FriendDBHandler.getInstance() # 2. Build GUI mainbox = wx.BoxSizer(wx.VERTICAL) # 3. Friends in top window #friendsbox_title = wx.StaticBox(self, -1, self.utility.lang.get('friends')) friendsbox = wx.BoxSizer(wx.VERTICAL) self.friendListCtrl = FriendList(self, self.friendsdb) friendsbox.Add(self.friendListCtrl, 1, wx.EXPAND|wx.TOP, 5) # 4. Buttons in lower window botbox = wx.BoxSizer(wx.HORIZONTAL) button = wx.Button(self, -1, self.utility.lang.get('buttons_add'), style = wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.addFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) button = wx.Button(self, -1, self.utility.lang.get('buttons_edit'), style = wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.editFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) button = wx.Button(self, -1, self.utility.lang.get('buttons_remove'), style = wx.BU_EXACTFIT) wx.EVT_BUTTON(self, button.GetId(), self.removeFriend) botbox.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) # 5. Show GUI mainbox.Add(friendsbox, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 5) mainbox.Add(botbox, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5) self.SetSizerAndFit(mainbox)
def OnAddEditFriend(self, event): name = self.name_text.GetValue() ip = str(self.ip_text.GetValue()) b64permid = str(self.permid_text.GetValue()) try: permid = base64.decodestring( b64permid+'\n' ) except: print_exc() permid = '' #icon = self.icon_path.GetValue() try: port = int(self.port_text.GetValue()) except: port = 0 if len(name) == 0: self.show_inputerror(self.utility.lang.get('nicknameempty_error')) elif len(permid) == 0: self.show_inputerror(self.utility.lang.get('friendspermid_error')) elif port == 0: self.show_inputerror(self.utility.lang.get('friendsport_error')) else: fdb = FriendDBHandler.getInstance() pdb = PeerDBHandler.getInstance() #friend = {'permid':permid, 'ip':ip, 'port':port, 'name':name, 'icon':newiconfilename} #friend = {'permid':permid, 'ip':ip, 'port':port, 'name':name} friend = {'ip':ip, 'port':port, 'name':name} if self.editfriend is not None: if self.editfriend['permid'] != permid: fdb.deleteFriend(self.editfriend['permid']) pdb.deletePeer(self.editfriend['permid']) #fdb.addExternalFriend(friend) pdb.addPeer(permid,friend) fdb.setFriend(permid) event.Skip() # must be done, otherwise ShowModal() returns wrong error self.Destroy() """
def OnAddEditFriend(self, event): name = self.name_text.GetValue() ip = str(self.ip_text.GetValue()) b64permid = str(self.permid_text.GetValue()) try: permid = base64.decodestring(b64permid + '\n') except: print_exc() permid = '' #icon = self.icon_path.GetValue() try: port = int(self.port_text.GetValue()) except: port = 0 if len(name) == 0: self.show_inputerror(self.utility.lang.get('nicknameempty_error')) elif len(permid) == 0: self.show_inputerror(self.utility.lang.get('friendspermid_error')) elif port == 0: self.show_inputerror(self.utility.lang.get('friendsport_error')) else: fdb = FriendDBHandler.getInstance() pdb = PeerDBHandler.getInstance() #friend = {'permid':permid, 'ip':ip, 'port':port, 'name':name, 'icon':newiconfilename} #friend = {'permid':permid, 'ip':ip, 'port':port, 'name':name} friend = {'ip': ip, 'port': port, 'name': name} if self.editfriend is not None: if self.editfriend['permid'] != permid: fdb.deleteFriend(self.editfriend['permid']) pdb.deletePeer(self.editfriend['permid']) #fdb.addExternalFriend(friend) pdb.addPeer(permid, friend) fdb.setFriend(permid) event.Skip( ) # must be done, otherwise ShowModal() returns wrong error self.Destroy() """