Stringfy the peer address.
JSON requires that the keys in dict must be strings.
This commit is contained in:
parent
5345ac37e1
commit
439ed70c6f
2 changed files with 6 additions and 2 deletions
|
@ -7,6 +7,7 @@ import threading
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
import math
|
import math
|
||||||
import pybase64
|
import pybase64
|
||||||
|
import json
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,7 +116,8 @@ class Peer(MessageServer):
|
||||||
for peer_address, possessed_chunks in chunkinfo.items():
|
for peer_address, possessed_chunks in chunkinfo.items():
|
||||||
if chunknum in possessed_chunks:
|
if chunknum in possessed_chunks:
|
||||||
if peer_address not in peers:
|
if peer_address not in peers:
|
||||||
peers[peer_address] = self._connect(peer_address)
|
# peer_address is a string, since JSON requires keys being strings
|
||||||
|
peers[peer_address] = self._connect(json.loads(peer_address))
|
||||||
# write the message to ask the chunk
|
# write the message to ask the chunk
|
||||||
self._write_message(peers[peer_address], {
|
self._write_message(peers[peer_address], {
|
||||||
'type': MessageType.PEER_REQUEST_CHUNK,
|
'type': MessageType.PEER_REQUEST_CHUNK,
|
||||||
|
|
|
@ -2,6 +2,7 @@ from p2pfs.core.server import MessageServer
|
||||||
from p2pfs.core.message import MessageType
|
from p2pfs.core.message import MessageType
|
||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class Tracker(MessageServer):
|
||||||
assert isinstance(client, socket.socket)
|
assert isinstance(client, socket.socket)
|
||||||
if message['type'] == MessageType.REQUEST_REGISTER:
|
if message['type'] == MessageType.REQUEST_REGISTER:
|
||||||
assert client in self._peers
|
assert client in self._peers
|
||||||
self._peers[client] = message['address']
|
# peer_address is a string, since JSON requires keys being strings
|
||||||
|
self._peers[client] = json.dumps(message['address'])
|
||||||
logger.debug(self._peers.values())
|
logger.debug(self._peers.values())
|
||||||
elif message['type'] == MessageType.REQUEST_PUBLISH:
|
elif message['type'] == MessageType.REQUEST_PUBLISH:
|
||||||
if message['filename'] in self._file_list:
|
if message['filename'] in self._file_list:
|
||||||
|
|
Loading…
Reference in a new issue