~ehmry/nim_tox

6c1bd56ed02f16a42a18344b6f8bebe0a1a9647f — Emery Hemingway 11 months ago d562256
SPOF bootstrap: Make IPv4 and IPv6 optional
1 files changed, 8 insertions(+), 7 deletions(-)

M src/toxcore/bootstrap.nim
M src/toxcore/bootstrap.nim => src/toxcore/bootstrap.nim +8 -7
@@ 7,7 7,8 @@ import std/asyncdispatch, std/httpclient, std/json

const spofNodeList* = "https://nodes.tox.chat/json"

proc bootstrapFromSpof*(tox: Tox) {.async.} =
proc bootstrapFromSpof*(tox: Tox; ipv4 = true; ipv6 = true) {.async.} =
  assert(ipv4 or ipv6)
  let
    http = newAsyncHttpClient()
    txt = await http.getContent(spofNodeList)


@@ 16,13 17,13 @@ proc bootstrapFromSpof*(tox: Tox) {.async.} =
  for num, node in js.pairs:
    try:
      let
        ipv4 = node["ipv4"].getStr("-")
        ipv6 = node["ipv6"].getStr("-")
        ip4 = node["ipv4"].getStr("-")
        ip6 = node["ipv6"].getStr("-")
        port = node["port"].getInt(toxcore.defaultPort.int).uint16
        key = node["public_key"].getStr.toPublicKey
      if ipv4 != "-":
        tox.bootstrap(ipv4, key, port)
      if ipv6 != "-":
        tox.bootstrap(ipv6, key, port)
      if ipv4 and ip4 != "-":
        tox.bootstrap(ip4, key, port)
      if ipv6 and ip6 != "-":
        tox.bootstrap(ip6, key, port)
    except:
      discard