@@ -84,7 +84,7 @@ def state_bm_header(self):
8484 """Process incoming header"""
8585 self .magic , self .command , self .payloadLength , self .checksum = \
8686 protocol .Header .unpack (self .read_buf [:protocol .Header .size ])
87- self .command = self .command .rstrip ('\x00 ' )
87+ self .command = self .command .rstrip (b '\x00 ' ). decode ( 'ascii' , 'replace ' )
8888 if self .magic != protocol .magic :
8989 # skip 1 byte in order to sync
9090 self .set_state ("bm_header" , length = 1 )
@@ -170,17 +170,17 @@ def decode_payload_node(self):
170170 """Decode node details from the payload"""
171171 # protocol.checkIPAddress()
172172 services , host , port = self .decode_payload_content ("Q16sH" )
173- if host [0 :12 ] == '\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \xFF \xFF ' :
174- host = socket .inet_ntop (socket .AF_INET , str (host [12 :16 ]))
175- elif host [0 :6 ] == '\xfd \x87 \xd8 \x7e \xeb \x43 ' :
173+ if host [0 :12 ] == b '\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \xFF \xFF ' :
174+ host = socket .inet_ntop (socket .AF_INET , bytes (host [12 :16 ]))
175+ elif host [0 :6 ] == b '\xfd \x87 \xd8 \x7e \xeb \x43 ' :
176176 # Onion, based on BMD/bitcoind
177- host = base64 .b32encode (host [6 :]).lower () + ".onion"
177+ host = base64 .b32encode (bytes ( host [6 :])). decode ( 'ascii' ).lower () + ".onion"
178178 else :
179- host = socket .inet_ntop (socket .AF_INET6 , str (host ))
179+ host = socket .inet_ntop (socket .AF_INET6 , bytes (host ))
180180 if host == "" :
181181 # This can happen on Windows systems which are not 64-bit
182182 # compatible so let us drop the IPv6 address.
183- host = socket .inet_ntop (socket .AF_INET , str (host [12 :16 ]))
183+ host = socket .inet_ntop (socket .AF_INET , bytes (host [12 :16 ]))
184184
185185 return Node (services , host , port )
186186
@@ -445,11 +445,11 @@ def bm_command_addr(self):
445445 """Incoming addresses, process them"""
446446 # not using services
447447 for seenTime , stream , _ , ip , port in self ._decode_addr ():
448- ip = str (ip )
448+ ip = bytes (ip )
449449 if (
450450 stream not in self .pool .streams
451451 # FIXME: should check against complete list
452- or ip .startswith ('bootstrap' )
452+ or ip .startswith (b 'bootstrap' )
453453 ):
454454 continue
455455 decodedIP = protocol .checkIPAddress (ip )
0 commit comments