LiquidAI-project / wasmiot-orchestrator

MIT License
0 stars 1 forks source link

11. Handling supervisor's `.local` suffix #13

Closed trkks closed 11 months ago

trkks commented 1 year ago
Author  'juaatark'
Created 2023-02-14T16:03:46.598+02:00
Updated 2023-02-23T10:24:54.061+02:00

With the current supervisor in my understanding on this line, the supervisor defines itself its special top level domain, but the node-library for mDNS (bonjour) does not remove this nor does Docker-compose seem to understand it when accessing the device by its internal (i.e., network created by Docker) hostname.

Currently this is handled by removing the suffix, which feels dumb.

Here's what querying HTTP on <hostname>.local results in on the orchestrator:

<-- log truncated -->
mDNS initialized; searching for hosts with {"type":"webthing"}
Listening on port: 3000
Found 'RNG-Box 100'! {
  "addresses": [
    "172.18.0.4"
  ],
  "name": "RNG-Box 100",
  "fqdn": "RNG-Box 100._webthing._tcp.local",
  "host": "04c2bb219d02",
  "referer": {
    "address": "172.18.0.4",
    "family": "IPv4",
    "port": 5353,
    "size": 215
  },
  "port": 3002,
  "type": "webthing",
  "protocol": "tcp",
  "subtypes": [],
  "rawTxt": {
    "type": "Buffer",
    "data": [
      0
    ]
  },
  "txt": {}
}
         Querying it (HTTP)... {"host":"04c2bb219d02","port":3002,"path":"/.well-known/wot-thing-description"}
The query on device at '04c2bb219d02' returned 200
Added new device description: {"architecture":"intel i7","platform":"Windows 11","repository":"TODO What dis?","peripherals":[]}
Found 'thingi'! {
  "addresses": [
    "172.18.0.3"
  ],
  "name": "thingi",
  "fqdn": "thingi._webthing._tcp.local",
  "host": "9951e1362ee2.local",
  "referer": {
    "address": "172.18.0.3",
    "family": "IPv4",
    "port": 5353,
    "size": 149
  },
  "port": 5000,
  "type": "webthing",
  "protocol": "tcp",
  "subtypes": [],
  "rawTxt": {
    "type": "Buffer",
    "data": [
      6,
      112,
      97,
      116,
      104,
      61,
      47,
      5,
      116,
      108,
      115,
      61,
      48
    ]
  },
  "txt": {
    "path": "/",
    "tls": "0"
  }
}
         Querying it (HTTP)... {"host":"9951e1362ee2.local","port":5000,"path":"/.well-known/wot-thing-description"}
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo EAI_AGAIN 9951e1362ee2.local
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (node:_http_client:496:9)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -3001,
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: '9951e1362ee2.local'
}
isoteemu commented 1 year ago

If you're removing the .local part, you're not using mdns name but the docker created static hostname. And the .local needs to be included in the discovery. https://www.w3.org/TR/wot-discovery/#introduction-dns-sd-sec

So in the above case you should be connecting - according the discovery - to the address returned by thingi._webthing._tcp.local, not the domain name, using the protocol it tells to use.

isoteemu commented 1 year ago

Check this shit out: https://gitlab.jyu.fi/wasmiot/flask-demo/-/blob/master/thingi/client.py

trkks commented 1 year ago

Ok so I now make the queries to devices on the first IP address in mDNS "responses" in 91e4c42e75041c5771d159a36b319e4228eeabde. This is probably not the intended way, but at least the devices should be available in non-Docker networks if I understood correctly?

trkks commented 1 year ago

Apparently there was another place where I forgot to remove this from, but should be all good now.