distributed: Add AIR.getNetworkAddress()

This commit is contained in:
Sam Edwards 2017-01-10 06:18:32 -07:00
parent dc80771337
commit 14f0d6e626
2 changed files with 37 additions and 0 deletions

View File

@ -244,6 +244,8 @@ class AstronInternalRepository(ConnectionRepository):
self.handleGetLocationResp(di)
elif msgType == STATESERVER_OBJECT_GET_ALL_RESP:
self.handleGetObjectResp(di)
elif msgType == CLIENTAGENT_GET_NETWORK_ADDRESS_RESP:
self.handleGetNetworkAddressResp(di)
elif msgType >= 20000:
# These messages belong to the NetMessenger:
self.netMessenger.handle(msgType, di)
@ -422,6 +424,39 @@ class AstronInternalRepository(ConnectionRepository):
finally:
del self.__callbacks[ctx]
def getNetworkAddress(self, clientId, callback):
"""
Get the endpoints of a client connection.
You should already be sure the client actually exists, otherwise the
callback will never be called.
Callback is called as: callback(remoteIp, remotePort, localIp, localPort)
"""
ctx = self.getContext()
self.__callbacks[ctx] = callback
dg = PyDatagram()
dg.addServerHeader(clientId, self.ourChannel, CLIENTAGENT_GET_NETWORK_ADDRESS)
dg.addUint32(ctx)
self.send(dg)
def handleGetNetworkAddressResp(self, di):
ctx = di.getUint32()
remoteIp = di.getString()
remotePort = di.getUint16()
localIp = di.getString()
localPort = di.getUint16()
if ctx not in self.__callbacks:
self.notify.warning('Received unexpected CLIENTAGENT_GET_NETWORK_ADDRESS_RESP (ctx: %d)' % ctx)
return
try:
self.__callbacks[ctx](remoteIp, remotePort, localIp, localPort)
finally:
del self.__callbacks[ctx]
def sendUpdate(self, do, fieldName, args):
"""
Send a field update for the given object.

View File

@ -123,6 +123,8 @@ MsgName2Id = {
'CLIENTAGENT_SEND_DATAGRAM': 1002,
'CLIENTAGENT_EJECT': 1004,
'CLIENTAGENT_DROP': 1005,
'CLIENTAGENT_GET_NETWORK_ADDRESS': 1006,
'CLIENTAGENT_GET_NETWORK_ADDRESS_RESP': 1007,
'CLIENTAGENT_DECLARE_OBJECT': 1010,
'CLIENTAGENT_UNDECLARE_OBJECT': 1011,
'CLIENTAGENT_ADD_SESSION_OBJECT': 1012,