Node: How to keep persistent incoming connection?

0

I've written a simple script "node" that will connect to the local node running on my computer.

I can see that it's connected using:

$ bitcoin-cli getpeerinfo

{
    "id": 27,
    "addr": "127.0.0.1:37992",
    "addrlocal": "127.0.0.1:18333",
    "services": "0000000000000001",
    "relaytxes": true,
    "lastsend": 1479746037,
    "lastrecv": 1479746037,
    "bytessent": 325460,
    "bytesrecv": 6007,
    "conntime": 1479745618,
    "timeoffset": 0,
    "pingwait": 419.673504,
    "version": 60002,
    "subver": "",
    "inbound": true,
    "startingheight": 0,
    "banscore": 0,
    "synced_headers": -1,
    "synced_blocks": -1,
    "inflight": [
    ],
    "whitelisted": false,
    "bytessent_per_msg": {
      "block": 236393,
      "getheaders": 1053,
      "inv": 5898,
      "ping": 32,
      "tx": 81934,
      "verack": 24,
      "version": 126
    },
    "bytesrecv_per_msg": {
      "getdata": 5898,
      "version": 109
    }
  }
}

However, the script will eventually lose connection to my local node and stop receiving messages. This usually happens within a space of an hour.

  • What causes a node to drop a connection to an incoming node?
  • Is it possible to make my local node to allow a permanent incoming connection (from my local script)?

EDIT: I've tried addnode=127.0.0.1 in my bitcoin.conf, but it doesn't help with reconnecting if the connection is dropped.

inersha

Posted 2016-11-21T16:33:11.827

Reputation: 2 236

1addnode just tells your node to consider connecting to that address. It doesn't treat inbound connections specially, or connect to the address.Nick ODell 2016-11-21T18:50:29.610

1Are you responding to ping requests? it may be dropping the connection because you look unresponsive.Pieter Wuille 2016-11-21T18:57:54.323

@PieterWuille. No, I've not been responding to ping requests. Thank you.inersha 2016-11-21T20:29:40.403

Answers

1

Solution: The node has been sending my script ping messages, but my script was not responding with pong messages.

The ping message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer. https://en.bitcoin.it/wiki/Protocol_documentation#ping

Therefore, my script "node" appeared to be unresponsive, so the local node would drop the connection.


Thanks to Pieter Wuille for pointing me in the right direction.

inersha

Posted 2016-11-21T16:33:11.827

Reputation: 2 236