Skip to content

Commit

Permalink
Pull laddress from a connected socket instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Jul 17, 2024
1 parent dc4d7c6 commit e1e9d0c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sippy/Wss_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ async def ws_to_sip(self, websocket, path):
sender = create_task(self.sip_to_ws(queue, websocket))
conn_id = f'{websocket.id}.invalid'
self.connections[conn_id] = (websocket, queue)
if self.uopts.laddress[0] == '0.0.0.0':
sock = websocket.transport.get_extra_info('socket')
addr = sock.getsockname()
ED2.callFromThread(self.set_laddress, addr)
address = Remote_address(websocket.remote_address, self.transport)
address.received = conn_id
try:
Expand All @@ -107,17 +111,17 @@ async def async_run(self):
subprotocols = ['sip']
)
server = await start_server
if self.uopts.laddress[0] == '0.0.0.0':
addr = server.sockets[0].getsockname()
self.uopts.laddress = addr
print(f'WSS server is listening on {addr[0]}:{addr[1]}')
await self.monitor_queue()
server.close()
await server.wait_closed()

def addr2str(self, address):
return f'{self.transport}:{address[0]}'

def set_laddress(self, address):
print(f'WSS server is listening on {address[0]}:{address[1]}')
self.uopts.laddress = address

def runFailed(self, exception):
ED2.breakLoop(255)
raise exception
Expand Down

0 comments on commit e1e9d0c

Please sign in to comment.