Wrong IP addresses registered when using Docker overlay network
- Dominant language
- Python
- Stars
- 157
- Forks
- 60
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 15
Description
Using ` 170: peername = request.transport.get_extra_info('peername')` in headnode.py fetches the node IP of the overlay network, and not the IP of the registering service/data node.
I replaced line 170 with a few lines of code into the register function to accept an 'addr' field from the registering node:
```python
if 'addr' not in body:
peername = request.transport.get_extra_info('peername')
if peername is None:
raise HTTPBadRequest(reason="Can not determine caller IP")
elif len(body['addr']) == 2:
peername = body['addr']
else:
raise HTTPBadRequest(reason="Can not determine caller IP")
```
and I added the following function to basenode.py to be invoked while sending the register signal:
```python
def getNodeIp(node_type):
""" Gets IP of local host (container) for the default route """
log.info("Node type: %s" % node_type)
if node_type == 'sn':
if config.get("sn_port"):
port = config.get("sn_port")
elif node_type == 'dn':
if config.get("dn_port"):
port = config.get("dn_port")
else:
port = 6101
IP = ((([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + ["no IP found"])[0], port)
log.info("sending node ip: %s:%s" % IP)
return IP
async def register(app):
""" register node with headnode
OK to call idempotently (e.g. if the headnode seems to have forgotten us)"""
head_url = getHeadUrl(app)
if not head_url:
log.warn("head_url is not set, can not register yet")
return
req_reg = head_url + "/register"
log.info("register: {}".format(req_reg))
addr = getNodeIp(app["node_type"])
if addr:
body = {"id": app["id"], "port": app["node_port"], "node_type": app["node_type"], "addr": addr}
else:
body = {"id": app["id"], "port": app["node_port"], "node_type": app["node_type"]}
.... etc
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.