bugfix
This commit is contained in:
parent
15aa886368
commit
8363720623
@ -30,7 +30,7 @@ class UdpWidget(EventDispatcher):
|
|||||||
evt_name = 'on_%s' % cmd
|
evt_name = 'on_%s' % cmd
|
||||||
setattr(self, evt_name, self.my_event_handler)
|
setattr(self, evt_name, self.my_event_handler)
|
||||||
self.register_event_type(evt_name)
|
self.register_event_type(evt_name)
|
||||||
print('udp_widget.py:register', evt_name, self.my_event_handler)
|
# print('udp_widget.py:register', evt_name, self.my_event_handler)
|
||||||
|
|
||||||
self.get_peer_pubkey()
|
self.get_peer_pubkey()
|
||||||
Clock.schedule_once(self.get_peer_pubkey_loop, 2)
|
Clock.schedule_once(self.get_peer_pubkey_loop, 2)
|
||||||
@ -51,7 +51,7 @@ class UdpWidget(EventDispatcher):
|
|||||||
self.get_peer_pubkey()
|
self.get_peer_pubkey()
|
||||||
|
|
||||||
def get_peer_pubkey(self, peer_id=None, timeout=1):
|
def get_peer_pubkey(self, peer_id=None, timeout=1):
|
||||||
print('get_peer_pubkey(), called..')
|
# print('get_peer_pubkey(), called..')
|
||||||
d = {
|
d = {
|
||||||
'c':'get_pubkey',
|
'c':'get_pubkey',
|
||||||
'd':{
|
'd':{
|
||||||
@ -61,7 +61,7 @@ class UdpWidget(EventDispatcher):
|
|||||||
bd = self.dataencoder.pack('none', d, uncrypt=True)
|
bd = self.dataencoder.pack('none', d, uncrypt=True)
|
||||||
self.udp_transport.broadcast(bd)
|
self.udp_transport.broadcast(bd)
|
||||||
if peer_id is None:
|
if peer_id is None:
|
||||||
print('get_peer_pubkey():return')
|
# print('get_peer_pubkey():return')
|
||||||
return
|
return
|
||||||
t = t1 = time.time()
|
t = t1 = time.time()
|
||||||
t1 += timeout
|
t1 += timeout
|
||||||
@ -73,30 +73,30 @@ class UdpWidget(EventDispatcher):
|
|||||||
raise Exception('timeout')
|
raise Exception('timeout')
|
||||||
|
|
||||||
def comm_callback(self, data, addr):
|
def comm_callback(self, data, addr):
|
||||||
print('comm_callback():', data, 'addr=', addr)
|
# print('comm_callback():', data, 'addr=', addr)
|
||||||
d = self.dataencoder.unpack(addr[0], data)
|
d = self.dataencoder.unpack(addr[0], data)
|
||||||
if d is None:
|
if d is None:
|
||||||
print('comm_callback(): d is None')
|
# print('comm_callback(): d is None')
|
||||||
return
|
return
|
||||||
if not isinstance(d, dict):
|
if not isinstance(d, dict):
|
||||||
print('comm_callback(): d is not a dict data')
|
# print('comm_callback(): d is not a dict data')
|
||||||
return
|
return
|
||||||
print('received: data=', d)
|
# print('received: data=', d)
|
||||||
cmd = d['c']
|
cmd = d['c']
|
||||||
f = self.inner_handlers.get(cmd)
|
f = self.inner_handlers.get(cmd)
|
||||||
if f:
|
if f:
|
||||||
f(d, addr)
|
f(d, addr)
|
||||||
print('comm_callback():inner callback called(),', cmd)
|
# print('comm_callback():inner callback called(),', cmd)
|
||||||
return
|
return
|
||||||
if cmd in self.block_commands:
|
if cmd in self.block_commands:
|
||||||
print('comm_callback():', cmd, 'is blocked')
|
# print('comm_callback():', cmd, 'is blocked')
|
||||||
return
|
return
|
||||||
evt_name = 'on_%s' % cmd
|
evt_name = 'on_%s' % cmd
|
||||||
evt_data = {
|
evt_data = {
|
||||||
'd': d,
|
'd': d,
|
||||||
'addr': addr
|
'addr': addr
|
||||||
}
|
}
|
||||||
print('udp_widget.py dispatch', evt_name, evt_data)
|
# print('udp_widget.py dispatch', evt_name, evt_data)
|
||||||
self.dispatch(evt_name, evt_data)
|
self.dispatch(evt_name, evt_data)
|
||||||
|
|
||||||
def my_event_handler(self, *args):
|
def my_event_handler(self, *args):
|
||||||
@ -105,12 +105,12 @@ class UdpWidget(EventDispatcher):
|
|||||||
def set_pubkey(self, data, addr):
|
def set_pubkey(self, data, addr):
|
||||||
pk = data['d']['pubkey']
|
pk = data['d']['pubkey']
|
||||||
id = addr[0]
|
id = addr[0]
|
||||||
print('set_pubkey(): ', id, pk)
|
# print('set_pubkey(): ', id, pk)
|
||||||
self.dataencoder.set_peer_text_pubkey(id, pk)
|
self.dataencoder.set_peer_text_pubkey(id, pk)
|
||||||
|
|
||||||
def resp_pubkey(self, data, addr):
|
def resp_pubkey(self, data, addr):
|
||||||
self.set_pubkey(data, addr)
|
self.set_pubkey(data, addr)
|
||||||
print('resp_pubkey():', addr[0])
|
# print('resp_pubkey():', addr[0])
|
||||||
data = {
|
data = {
|
||||||
'c':'set_pubkey',
|
'c':'set_pubkey',
|
||||||
'd':{
|
'd':{
|
||||||
@ -124,7 +124,7 @@ class UdpWidget(EventDispatcher):
|
|||||||
self.send(peer, data)
|
self.send(peer, data)
|
||||||
|
|
||||||
def send(self, peer_id, data, uncrypt=False):
|
def send(self, peer_id, data, uncrypt=False):
|
||||||
print('send():', peer_id, data)
|
# print('send():', peer_id, data)
|
||||||
d = self.dataencoder.pack(peer_id, data, uncrypt=uncrypt)
|
d = self.dataencoder.pack(peer_id, data, uncrypt=uncrypt)
|
||||||
addr = (peer_id, self.udp_port)
|
addr = (peer_id, self.udp_port)
|
||||||
self.udp_transport.send(d, addr)
|
self.udp_transport.send(d, addr)
|
||||||
|
Loading…
Reference in New Issue
Block a user