Exemplo n.º 1
0
 def UpdatePeer(self, peer):
     """
     Called when a peer has changed.
     """
     peer_id = peer.id_
     old_peer = self.peers[peer_id]
     self.peers[peer_id] = peer
     # Compare the peer's old services to its new ones...
     new_ids = set([_service.id_ for _service in peer.GetServices()])
     old_ids = set([_service.id_ for _service in old_peer.GetServices()])
     # Notify removed services
     for service_id in old_ids - new_ids:
         try:
             plugin = self.plugins[service_id]
         except KeyError:
             pass
         else:
             plugin.LostPeer(peer_id)
     # Notify added services
     for service_id in new_ids - old_ids:
         try:
             plugin = self.plugins[service_id]
         except KeyError:
             pass
         else:
             plugin.NewPeer(peer, peer.GetService(service_id))
     # Notify updated services
     for service_id in new_ids & old_ids:
         try:
             plugin = self.plugins[service_id]
         except KeyError:
             pass
         else:
             plugin.ChangedPeer(peer, peer.GetService(service_id))
Exemplo n.º 2
0
 def StripMessage(self, message):
     """
     Strip unnecessary parameters from message.
     """
     required_args = set([ATTRIBUTE_NAMES[arg_id] for arg_id in REQUESTS[message.request]])
     args = message.args
     for k in set(args.__dict__) - required_args:
         delattr(args, k)
Exemplo n.º 3
0
 def Init(self, local_ip):
     self.avatars = AvatarRepository()
     self.reactor = self.service_api.GetReactor()
     self.host = local_ip
     self.port = 7780 + random.randrange(0, 100)
     # Network address container: { peer_id => (host, port) }
     self.hosts = {}
     self.node_avatar_hash = None
     self.node_id = None
     # Peers for which we have received an avatar hash but whose
     # address we don't know yet
     self.pending_peers = set()
 def OnAddBookmark(self, event): # wxGlade: BookmarksDialog.<event_handler>
     all_peers = self.world.GetAllPeers()
     bookmarked_peers = set([peer.id_ for peer in self.bookmarks.GetAllPeers()])
     peers = [peer for peer in all_peers if peer.id_ not in bookmarked_peers]
     dialog = wx.SingleChoiceDialog(parent=self,
         message=_("Please choose the peer to add to your bookmarks list."),
         caption=_("Add bookmark"),
         choices=[peer.pseudo for peer in peers])
     if dialog.ShowModal() == wx.ID_OK:
         peer = peers[dialog.GetSelection()]
         self.bookmarks.AddPeer(peer)
         self.UpdateUI()
Exemplo n.º 5
0
 def Init(self):
     self.avatars = AvatarRepository()
     self.reactor = self.service_api.GetReactor()
     # TODO: smartly discover our own address IP
     # (this is where duplicated code starts to appear...)
     self.host = socket.gethostbyname(socket.gethostname())
     self.port = 7780 + random.randrange(0, 100)
     # Network address container: { peer_id => (host, port) }
     self.hosts = {}
     self.node_avatar_hash = None
     self.node_id = None
     # Peers for which we have received an avatar hash but whose
     # address we don't know yet
     self.pending_peers = set()
    def __init__(self, app, world, config_data, menu, *args, **kwds):
        self.app = app
        self.world = world
        self.config_data = config_data
        self.menu = menu

        # Item index => peer
        self.item_map = {}
        # Peer IDs
        self.selected_items = set()
        # Menu items
        self.menu_items = []

        # begin wxGlade: BookmarksDialog.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        
        # Tool Bar
        self.toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL|wx.TB_TEXT|wx.TB_HORZ_LAYOUT|wx.TB_HORZ_TEXT)
        self.SetToolBar(self.toolbar)
        self.toolbar.AddLabelTool(TOOL_ADD_BOOKMARK, _("Add bookmark"), (TB(wx.ART_ADD_BOOKMARK)), wx.NullBitmap, wx.ITEM_NORMAL, _("Remember one of your current neighbours"), "")
        self.toolbar.AddLabelTool(TOOL_DEL_BOOKMARK, _("Remove"), (TB(wx.ART_DEL_BOOKMARK)), wx.NullBitmap, wx.ITEM_NORMAL, _("Remove selected bookmark"), "")
        self.toolbar.AddLabelTool(TOOL_PROPERTIES, _("Information"), (TB(wx.ART_FILE_OPEN)), wx.NullBitmap, wx.ITEM_NORMAL, _("Get bookmark information"), "")
        # Tool Bar end
        self.list_ctrl = wx.ListCtrl(self.panel_1, -1, style=wx.LC_REPORT|wx.LC_VRULES|wx.SUNKEN_BORDER)
        self.button_close = wx.Button(self.panel_1, wx.ID_CLOSE, "")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TOOL, self.OnAddBookmark, id=TOOL_ADD_BOOKMARK)
        self.Bind(wx.EVT_TOOL, self.OnDelBookmark, id=TOOL_DEL_BOOKMARK)
        self.Bind(wx.EVT_TOOL, self.OnProperties, id=TOOL_PROPERTIES)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnDeselectItem, self.list_ctrl)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectItem, self.list_ctrl)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnActivateItem, self.list_ctrl)
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
        # end wxGlade
        self.Bind(wx.EVT_SHOW, self.OnShow)
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.config_data.AskNotify(self.ApplyConfig)
        self.ApplyConfig()
    def __init__(self, app, world, bookmarks, menu, *args, **kwds):
        self.app = app
        self.world = world
        self.bookmarks = bookmarks
        self.menu = menu

        # Item index => peer
        self.item_map = {}
        # Peer IDs
        self.selected_items = set()
        # Menu items
        self.menu_items = []

        # begin wxGlade: BookmarksDialog.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        
        # Tool Bar
        self.toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL|wx.TB_TEXT|wx.TB_HORZ_LAYOUT|wx.TB_HORZ_TEXT)
        self.SetToolBar(self.toolbar)
        self.toolbar.AddLabelTool(TOOL_ADD_BOOKMARK, _("Add bookmark"), (TB(wx.ART_ADD_BOOKMARK)), wx.NullBitmap, wx.ITEM_NORMAL, _("Bookmark a node"), "")
        self.toolbar.AddLabelTool(TOOL_DEL_BOOKMARK, _("Remove"), (TB(wx.ART_DEL_BOOKMARK)), wx.NullBitmap, wx.ITEM_NORMAL, _("Remove selected bookmark"), "")
        # Tool Bar end
        self.list_ctrl = wx.ListCtrl(self.panel_1, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.button_close = wx.Button(self.panel_1, wx.ID_CLOSE, "")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TOOL, self.OnAddBookmark, id=TOOL_ADD_BOOKMARK)
        self.Bind(wx.EVT_TOOL, self.OnDelBookmark, id=TOOL_DEL_BOOKMARK)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnDeselectItem, self.list_ctrl)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectItem, self.list_ctrl)
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
        # end wxGlade
        self.Bind(wx.EVT_SHOW, self.OnShow)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
Exemplo n.º 8
0
    def _NecessaryPeers(self, max_angle=None):
        """
        Returns id's of peers that are necessary for our global connectivity.
        """
        if len(self.peers) < 3:
            return self.peers.keys()
        if max_angle is None:
            max_angle = self.max_angle
        _angles = self.angle_peers
        pi2 = 2.0 * math.pi

        result = set()
        prev_angle, _ = _angles[-2]
        angle, id_ = _angles[-1]
        # For each peer, we check the angle between the predecessor and
        # the successor. If the angle is greater than the desired max angle,
        # then this peer is necessary.
        for next_angle, next_id in _angles:
            if (next_angle - prev_angle) % pi2 >= max_angle:
                result.add(id_)
            prev_angle = angle
            angle, id_ = next_angle, next_id

        return result
Exemplo n.º 9
0
 def PeersSet(self):
     """
     Returns a set of all peer ids.
     """
     return set(self.peers.iterkeys())
Exemplo n.º 10
0
 def Reset(self):
     self.plugins = {}
     self.peers = {}
     self.enabled_services = set()