rpc: Add listen address to incoming connections in getpeerinfo #10478

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2017_05_peer_listenaddr changing 6 files +53 −13
  1. laanwj commented at 10:00 am on May 30, 2017: member

    This adds the listening address on which incoming connections were received to the CNode and CNodeStats structures.

    The address is reported in getpeerinfo.

    This can be useful for distinguishing connections received on different listening ports (e.g. when using a different listening port for Tor hidden service connections) or different networks.

  2. laanwj added the label P2P on May 30, 2017
  3. laanwj added the label RPC/REST/ZMQ on May 30, 2017
  4. in src/net.cpp:1043 in 63c7158235 outdated
    1041-    if (hSocket != INVALID_SOCKET)
    1042-        if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
    1043+    if (hSocket != INVALID_SOCKET) {
    1044+        if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) {
    1045             LogPrintf("Warning: Unknown socket family\n");
    1046+	}
    


    ryanofsky commented at 3:18 pm on May 30, 2017:
    Should replace tab with spaces here.
  5. in src/rpc/net.cpp:137 in 63c7158235 outdated
    132@@ -133,6 +133,8 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
    133         obj.push_back(Pair("addr", stats.addrName));
    134         if (!(stats.addrLocal.empty()))
    135             obj.push_back(Pair("addrlocal", stats.addrLocal));
    136+        if (stats.addrListen.IsValid())
    137+            obj.push_back(Pair("addrlisten", stats.addrListen.ToString()));
    


    ryanofsky commented at 3:29 pm on May 30, 2017:

    getpeerinfo help string needs to be updated

    Would be nice to test this from python as well.

  6. in src/net.h:509 in 63c7158235 outdated
    505@@ -506,6 +506,8 @@ class CNodeStats
    506     double dMinPing;
    507     std::string addrLocal;
    508     CAddress addr;
    509+    // Bind address that this connection came in on (for incoming connections)
    


    ryanofsky commented at 3:37 pm on May 30, 2017:
    I think it would be helpful if you could add comments for addr and addrLocal above, they contain “ip address and port of the peer” and “local address” according to RPC documention, and say specifically how addrListen is different from addrLocal.

    laanwj commented at 4:16 pm on May 30, 2017:
    Yes, addrLocal is pretty much useless in most cases, as it’s what is sent by the peer. Wish we could rename that one. But yes it needs to be documented.

    gmaxwell commented at 4:39 pm on May 30, 2017:
    bogoip :P
  7. ryanofsky commented at 3:53 pm on May 30, 2017: member

    Slightly tested ACK 63c71582352f62d1ba674f09a5c00b93dd6f9284.

    I would maybe consider renaming addrlisten to addrbind and not just restricting it to incoming connections.

  8. laanwj commented at 4:14 pm on May 30, 2017: member

    I would maybe consider renaming addrlisten to addrbind and not just restricting it to incoming connections.

    Good point. We could also call getsockname for for outgoing connections, though the meaning is somewhat more obscure.

    We use both bind and listen in command line options so I wasn’t sure what to call it, but you’re right it correlates more with bind’s meaning.

  9. in src/rpc/net.cpp:138 in a501d01491 outdated
    133@@ -133,8 +134,8 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
    134         obj.push_back(Pair("addr", stats.addrName));
    135         if (!(stats.addrLocal.empty()))
    136             obj.push_back(Pair("addrlocal", stats.addrLocal));
    137-        if (stats.addrListen.IsValid())
    138-            obj.push_back(Pair("addrlisten", stats.addrListen.ToString()));
    139+        if (stats.addrBind.IsValid())
    140+            obj.push_back(Pair("addrlisten", stats.addrBind.ToString()));
    


    ryanofsky commented at 2:13 pm on May 31, 2017:
    “addrlisten” string needs to be updated here

    laanwj commented at 3:07 pm on May 31, 2017:
    Eh yes
  10. ryanofsky commented at 2:14 pm on May 31, 2017: member
    utACK a501d01491745f5b78d4ae484d50c2bcdb5d4700 with one comment. Thanks for taking some of my suggestions.
  11. laanwj commented at 3:07 pm on May 31, 2017: member
    @ryanofsky yes, should have gotten most of them, I still intend to add a python tests. Now that both incoming and outgoing connections have the addrbind it’s possible to correlate 100% the connection ids between local nodes.
  12. rpc: Add listen address to incoming connections in `getpeerinfo`
    This adds the listening address on which incoming connections were received to the
    CNode and CNodeStats structures.
    
    The address is reported in `getpeerinfo`.
    
    This can be useful for distinguishing connections received on different listening ports
    (e.g. when using a different listening port for Tor hidden service connections)
    or different networks.
    a7e3c2814c
  13. test: Add test for `getpeerinfo` `bindaddr` field 3457331386
  14. laanwj force-pushed on Jun 5, 2017
  15. laanwj commented at 11:58 am on June 5, 2017: member
    Rebased, squashed, and added a basic python test.
  16. laanwj merged this on Jun 5, 2017
  17. laanwj closed this on Jun 5, 2017

  18. laanwj referenced this in commit 296928eb38 on Jun 5, 2017
  19. PastaPastaPasta referenced this in commit f870c8c975 on Jun 20, 2019
  20. PastaPastaPasta referenced this in commit f178ee596c on Jun 20, 2019
  21. PastaPastaPasta referenced this in commit 8c9ac817bb on Jun 22, 2019
  22. PastaPastaPasta referenced this in commit 0ab42caa05 on Jun 22, 2019
  23. PastaPastaPasta referenced this in commit acd6c12826 on Jun 22, 2019
  24. PastaPastaPasta referenced this in commit 18bf8ff480 on Jun 22, 2019
  25. PastaPastaPasta referenced this in commit 666e601389 on Jun 22, 2019
  26. PastaPastaPasta referenced this in commit f842455338 on Jun 22, 2019
  27. PastaPastaPasta referenced this in commit f533456cec on Jun 22, 2019
  28. PastaPastaPasta referenced this in commit 5271a2c5fa on Jun 22, 2019
  29. PastaPastaPasta referenced this in commit 86f8ed236c on Jun 22, 2019
  30. PastaPastaPasta referenced this in commit bf2f359214 on Jun 22, 2019
  31. PastaPastaPasta referenced this in commit 44a55019b4 on Jun 26, 2019
  32. barrystyle referenced this in commit 25ffd58b20 on Jan 22, 2020
  33. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-30 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me