-
Notifications
You must be signed in to change notification settings - Fork 33
Added IPV6 support #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,13 +37,15 @@ def handle(self): | |
| self.handle_store(message) | ||
| except KeyError, ValueError: | ||
| pass | ||
| client_host, client_port = self.client_address | ||
| client_host = self.client_address[0] | ||
| client_port = self.client_address[1] | ||
| peer_id = message["peer_id"] | ||
| new_peer = Peer(client_host, client_port, peer_id) | ||
| self.server.dht.buckets.insert(new_peer) | ||
|
|
||
| def handle_ping(self, message): | ||
| client_host, client_port = self.client_address | ||
| client_host = self.client_address[0] | ||
| client_port = self.client_address[1] | ||
| id = message["peer_id"] | ||
| peer = Peer(client_host, client_port, id) | ||
| peer.pong(socket=self.server.socket, peer_id=self.server.dht.peer.id, lock=self.server.send_lock) | ||
|
|
@@ -54,7 +56,8 @@ def handle_pong(self, message): | |
| def handle_find(self, message, find_value=False): | ||
| key = message["id"] | ||
| id = message["peer_id"] | ||
| client_host, client_port = self.client_address | ||
| client_host = self.client_address[0] | ||
| client_port = self.client_address[1] | ||
| peer = Peer(client_host, client_port, id) | ||
| response_socket = self.request[1] | ||
| if find_value and (key in self.server.dht.data): | ||
|
|
@@ -86,19 +89,21 @@ def handle_store(self, message): | |
|
|
||
|
|
||
| class DHTServer(SocketServer.ThreadingMixIn, SocketServer.UDPServer): | ||
| def __init__(self, host_address, handler_cls): | ||
| def __init__(self, host_address, handler_cls, ipv6): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep the API functional, should use a default parameter. |
||
| self.address_family = socket.AF_INET6 if ipv6 else socket.AF_INET | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation |
||
| SocketServer.UDPServer.__init__(self, host_address, handler_cls) | ||
| self.send_lock = threading.Lock() | ||
|
|
||
| class DHT(object): | ||
| def __init__(self, host, port, id=None, boot_host=None, boot_port=None): | ||
| if not id: | ||
| id = random_id() | ||
| ipv6 = True | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tab vs. space |
||
| self.peer = Peer(unicode(host), port, id) | ||
| self.data = {} | ||
| self.buckets = BucketSet(k, id_bits, self.peer.id) | ||
| self.rpc_ids = {} # should probably have a lock for this | ||
| self.server = DHTServer(self.peer.address(), DHTRequestHandler) | ||
| self.server = DHTServer(self.peer.address(), DHTRequestHandler, ipv6) | ||
| self.server.dht = self | ||
| self.server_thread = threading.Thread(target=self.server.serve_forever) | ||
| self.server_thread.daemon = True | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless change?