mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 18:25:21 +00:00
lnbase: parse ipv6, fix transport bug
This commit is contained in:
parent
f68b186be0
commit
9088b25a06
1 changed files with 14 additions and 10 deletions
|
@ -310,6 +310,8 @@ class Peer(PrintError):
|
||||||
self.temporary_channel_id_to_incoming_funding_signed = {}
|
self.temporary_channel_id_to_incoming_funding_signed = {}
|
||||||
self.init_message_received_future = asyncio.Future()
|
self.init_message_received_future = asyncio.Future()
|
||||||
self.localfeatures = 0x08 # request initial sync
|
self.localfeatures = 0x08 # request initial sync
|
||||||
|
self.nodes = {} # received node announcements
|
||||||
|
self.channels = {} # received channel announcements
|
||||||
|
|
||||||
def diagnostic_name(self):
|
def diagnostic_name(self):
|
||||||
return self.host
|
return self.host
|
||||||
|
@ -330,8 +332,8 @@ class Peer(PrintError):
|
||||||
self.writer.write(lc+c)
|
self.writer.write(lc+c)
|
||||||
|
|
||||||
async def read_message(self):
|
async def read_message(self):
|
||||||
rn_l = self.rn()
|
rn_l, rk_l = self.rn()
|
||||||
rn_m = self.rn()
|
rn_m, rk_m = self.rn()
|
||||||
while True:
|
while True:
|
||||||
s = await self.reader.read(2**10)
|
s = await self.reader.read(2**10)
|
||||||
if not s:
|
if not s:
|
||||||
|
@ -340,14 +342,14 @@ class Peer(PrintError):
|
||||||
if len(self.read_buffer) < 18:
|
if len(self.read_buffer) < 18:
|
||||||
continue
|
continue
|
||||||
lc = self.read_buffer[:18]
|
lc = self.read_buffer[:18]
|
||||||
l = aead_decrypt(self.rk, rn_l, b'', lc)
|
l = aead_decrypt(rk_l, rn_l, b'', lc)
|
||||||
length = int.from_bytes(l, byteorder="big")
|
length = int.from_bytes(l, byteorder="big")
|
||||||
offset = 18 + length + 16
|
offset = 18 + length + 16
|
||||||
if len(self.read_buffer) < offset:
|
if len(self.read_buffer) < offset:
|
||||||
continue
|
continue
|
||||||
c = self.read_buffer[18:offset]
|
c = self.read_buffer[18:offset]
|
||||||
self.read_buffer = self.read_buffer[offset:]
|
self.read_buffer = self.read_buffer[offset:]
|
||||||
msg = aead_decrypt(self.rk, rn_m, b'', c)
|
msg = aead_decrypt(rk_m, rn_m, b'', c)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
async def handshake(self):
|
async def handshake(self):
|
||||||
|
@ -385,7 +387,7 @@ class Peer(PrintError):
|
||||||
self.s_ck = ck
|
self.s_ck = ck
|
||||||
|
|
||||||
def rn(self):
|
def rn(self):
|
||||||
o = self._rn
|
o = self._rn, self.rk
|
||||||
self._rn += 1
|
self._rn += 1
|
||||||
if self._rn == 1000:
|
if self._rn == 1000:
|
||||||
self.r_ck, self.rk = get_bolt8_hkdf(self.r_ck, self.rk)
|
self.r_ck, self.rk = get_bolt8_hkdf(self.r_ck, self.rk)
|
||||||
|
@ -447,6 +449,7 @@ class Peer(PrintError):
|
||||||
def read(n):
|
def read(n):
|
||||||
data, self.s = self.s[0:n], self.s[n:]
|
data, self.s = self.s[0:n], self.s[n:]
|
||||||
return data
|
return data
|
||||||
|
addresses = []
|
||||||
while self.s:
|
while self.s:
|
||||||
atype = ord(read(1))
|
atype = ord(read(1))
|
||||||
if atype == 0:
|
if atype == 0:
|
||||||
|
@ -455,15 +458,16 @@ class Peer(PrintError):
|
||||||
ipv4_addr = '.'.join(map(lambda x: '%d'%x, read(4)))
|
ipv4_addr = '.'.join(map(lambda x: '%d'%x, read(4)))
|
||||||
port = int.from_bytes(read(2), byteorder="big")
|
port = int.from_bytes(read(2), byteorder="big")
|
||||||
x = ipv4_addr, port, binascii.hexlify(pubkey)
|
x = ipv4_addr, port, binascii.hexlify(pubkey)
|
||||||
self.print_error('node announcement', x)
|
addresses.append((ipv4_addr, port))
|
||||||
node_list.append(x)
|
|
||||||
elif atype == 2:
|
elif atype == 2:
|
||||||
ipv6_addr = read(16)
|
ipv6_addr = b':'.join([binascii.hexlify(read(2)) for i in range(4)])
|
||||||
port = read(2)
|
port = int.from_bytes(read(2), byteorder="big")
|
||||||
print(ipv6_addr, port)
|
addresses.append((ipv6_addr, port))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
continue
|
continue
|
||||||
|
self.print_error('node announcement', binascii.hexlify(pubkey), addresses)
|
||||||
|
self.nodes[pubkey] = {'addresses': addresses}
|
||||||
|
|
||||||
def on_init(self, payload):
|
def on_init(self, payload):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue