Exemplo n.º 1
0
    def announcePeer(self, info_hash, port, khashmir_id):
        assert type(port) == type(1)
        assert type(info_hash) == type('')
        assert type(khashmir_id) == type('')
        assert len(info_hash) == 20
        assert len(khashmir_id) == 20

        try:
            token = self.table.tcache[self.id]
        except:
            token = None
        if token:
            assert type(token) == type("")
            assert len(token) == 20
            df = self.conn().sendRequest(
                'announce_peer', {
                    'info_hash': info_hash,
                    'port': port,
                    'id': khashmir_id,
                    'token': token
                })
        else:
            raise KRPCProtocolError("no write token for node")
        df.addErrback(self.errBack)
        df.addCallback(self.checkSender)
        return df
Exemplo n.º 2
0
 def krpc_announce_peer(self, info_hash, port, id, token, _krpc_sender):
     sender = {'id': id}
     sender['host'] = _krpc_sender[0]
     sender['port'] = _krpc_sender[1]
     if not self.val_token(token, sender['host'], sender['port']):
         raise KRPCProtocolError("Invalid Write Token")
     value = compact_peer_info(_krpc_sender[0], port)
     self.store[info_hash] = value
     n = self.Node().initWithDict(sender)
     self.insertNode(n, contacted=0)
     return {"id": self.node.id}