minima-global / Minima

The Minima protocol Java libraries and application
Apache License 2.0
129 stars 146 forks source link

Minima IPv6 quick and dirty POC #622

Open towelbyte opened 1 day ago

towelbyte commented 1 day ago

This is a quick and dirty hack, but working prototype, for Minima partial IPv6 support as a proof of concept; for demonstration purposes.

This allows for peers IP:PORT to be defined for IPv6 addresses as well, by simple notation: e.g.: fda9:e0aa:589f::2:9001. For proper implementation we may want to only allow the unambiguous square brackets notation, e.g.: [fda9:e0aa:589f::2]:9001 ?

For proper implementation we may want to filter-out "local" addresses: link local (fe80::/10) and unique local (fc00::/7), and loopback (::1/128). Analogous as the code currently does with IPv4 (and then an -allip option override).

Testing: Running on testnet in docker containers w/ unique local IPv6 addresses.

Can send messages over Maxima; Maxima contact addresses w/ IPv6:

"contact":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G13P2JWVKB65Y6C9H4SCM03RY9DRFSBYDAVTRZ3286DRC6426MHAEZZ3GB8G23VCR5EWN82R22843R34056M06Z6BQEY6SJKYGEWZZ3J9T9WHFHSVNFBS222YA0QDAVYGGGNR4HSBNZ87JNHFAJ08ZQQVMP64M1GHHDSEHCEUZ110303NJBW1TUGD5D3CTK0Z5UD3QBSDVFZUUK10608006QWVV1A@fda9:e0aa:589f:0:0:0:0:4:9001"

This does mean that such a node may not be able to communicate over Maxima with a node that may only be connectable via IPv4 (as this node's maxima contact address has only an IPv6 relay address).

The current assumption is there is 1 relay IPv4 address in the Maxima contact address. If adding IPv6 support, maybe Maxima addresses could be extended to be able to have 1 or more IPv4 and/or IPv6 addresses of relay nodes? Maybe simply separated by a comma? e.g.:

"contact":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G13P2JWVKB65Y6C9H4SCM03RY9DRFSBYDAVTRZ3286DRC6426MHAEZZ3GB8G23VCR5EWN82R22843R34056M06Z6BQEY6SJKYGEWZZ3J9T9WHFHSVNFBS222YA0QDAVYGGGNR4HSBNZ87JNHFAJ08ZQQVMP64M1GHHDSEHCEUZ110303NJBW1TUGD5D3CTK0Z5UD3QBSDVFZUUK10608006QWVV1A@fda9:e0aa:589f:0:0:0:0:4:9001,172.20.0.4"

There may be additional backwards compatibility considerations to think of.

node 2: Add initial peer as an IPv6 address:port

peers action:addpeers peerslist:fda9:e0aa:589f::2:9001
{
  "command":"peers",
  "params":{
    "action":"addpeers",
    "peerslist":"fda9:e0aa:589f::2:9001"
  },
  "status":true,
  "pending":false,
  "response":{
    "valid":"[fda9:e0aa:589f::2:9001]",
    "invalid":"[]",
    "message":"Valid peers added to checking queue.."
  }
}

node 1: after node 2 has added it as its initial peer:

Minima @ 06/11/2024 15:50:58 [386.2 MB] : [D] [+] Setting My IP: fda9:e0aa:589f:0:0:0:0:2
Minima @ 06/11/2024 15:50:58 [386.3 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0

Minima @ 06/11/2024 15:50:47 [378.7 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:50:57 [385.2 MB] : [D] [-] Prevent node from adding localhost address to peers list 172.20.0.3
Minima @ 06/11/2024 15:50:58 [386.2 MB] : [D] [+] Setting My IP: fda9:e0aa:589f:0:0:0:0:2
Minima @ 06/11/2024 15:50:58 [386.3 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:51:04 [53.6 MB] : [D] [!] P2P requesting NIO connection to: fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:04 [56.3 MB] : Connected attempt success to fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:04 [56.4 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:51:04 [297.6 MB] : Setting MLS server : MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G14HG3ZTZ4DB1FJN0D1KC3HDBVE0YRP1SF98B9HF025C2YRYP3YET89W76RNHD05YE5EDGVZ6C773H9CWA06NAYKDWTHNKEG76DZKM9GV2NSMA8W9ZDHEBWTJ63F80RCSWTGNMS82YF9PHZB3EHF3CC1C72BEGVW71CDMS4W25RUEK5A2P60PHCG7BMACAMRFVEAJB79FWS5644106080069RQS2N@fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:08 [107.9 MB] : [D] [-] Prevent node from adding localhost address to peers list 172.20.0.3
Minima @ 06/11/2024 15:51:11 [64.8 MB] : Re-Calculate device hash rate : 0.3974 MHs
Minima @ 06/11/2024 15:51:15 [66.7 MB] : [D] [-] Prevent node from adding localhost address to peers list 172.20.0.3
Minima @ 06/11/2024 15:51:16 [66.8 MB] : [D] Attempting to scale outlinks
Minima @ 06/11/2024 15:51:16 [67.0 MB] : [D] [+] Walk to scale out-links returned. Path: [/fda9:e0aa:589f:0:0:0:0:2:9001, /fda9:e0aa:589f:0:0:0:0:3:9001] Connecting to node: /fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:16 [67.0 MB] : [D] [!] P2P requesting NIO connection to: fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:16 [67.2 MB] : Connected attempt success to fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:16 [67.6 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:51:16 [96.1 MB] : INVALID MAXCHECK REC:17DDVDPKI0692 FROM:2H9KEAV12A7AB Could be multiple connections to the same Host..? @ fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:22 [37.9 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:51:28 [115.1 MB] : [D] Attempting to scale outlinks
Minima @ 06/11/2024 15:51:28 [115.2 MB] : [D] [+] Walk to scale out-links returned. Path: [/fda9:e0aa:589f:0:0:0:0:2:9001, /fda9:e0aa:589f:0:0:0:0:3:9001] Connecting to node: /fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:28 [115.2 MB] : [D] [!] P2P requesting NIO connection to: fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:28 [115.4 MB] : Connected attempt success to fda9:e0aa:589f:0:0:0:0:3:9001
Minima @ 06/11/2024 15:51:28 [115.7 MB] : [+] Connected to the blockchain Initial Block Download received. size:5 bytes blocks:0
Minima @ 06/11/2024 15:51:28 [75.9 MB] : INVALID MAXCHECK REC:FQT0DJMD2QQHL FROM:2H9KEAV12A7AB Could be multiple connections to the same Host..? @ fda9:e0aa:589f:0:0:0:0:3:9001

Netstat shows connections via IPv4 and IPv6. I don't know why multiple connections to the same IP:PORT occur, though.

minima@e4eb767f3b14:~$ netstat -tuapn | grep java | grep ESTABLISHED
tcp6       0      0 fda9:e0aa:589f::2:34208 fda9:e0aa:589f::3:9001  ESTABLISHED 589/java                      
tcp6       0      0 fda9:e0aa:589f::2:50740 fda9:e0aa:589f::4:9001  ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:55990 fda9:e0aa:589f::4:9001  ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:9001  fda9:e0aa:589f::3:42910 ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:54086 fda9:e0aa:589f::3:9001  ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:9001  fda9:e0aa:589f::3:34920 ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:9001  fda9:e0aa:589f::4:55726 ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:9001  fda9:e0aa:589f::3:60330 ESTABLISHED 589/java            
tcp6       0      0 fda9:e0aa:589f::2:52198 fda9:e0aa:589f::4:9001  ESTABLISHED 589/java                    
tcp6       0      0 fda9:e0aa:589f::2:9001  fda9:e0aa:589f::4:49050 ESTABLISHED 589/java            
minima@e4eb767f3b14:~$ 

with -allip option:

minima@5a111f8fac23:~$ netstat -tuapn | grep ESTAB
tcp6       0      0 fda9:e0aa:589f::4:36606 fda9:e0aa:589f::2:9001  ESTABLISHED 2088/java           
tcp6       0      0 172.20.0.4:37880        172.20.0.3:9001         ESTABLISHED 2088/java           
tcp6       0      0 172.20.0.4:51088        172.20.0.4:9001         ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:9001  fda9:e0aa:589f::3:38640 ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:9001  fda9:e0aa:589f::2:52656 ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:54690 fda9:e0aa:589f::3:9001  ESTABLISHED 2088/java           
tcp6       0      0 172.20.0.4:9001         172.20.0.4:51088        ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:52848 fda9:e0aa:589f::2:9001  ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:9001  fda9:e0aa:589f::3:47452 ESTABLISHED 2088/java           
tcp6       0      0 fda9:e0aa:589f::4:9001  fda9:e0aa:589f::2:57928 ESTABLISHED 2088/java 
status
{
  "command":"status",
  "status":true,
  "pending":false,
  "response":{
    "version":"1.0.41-TEST",
    "uptime":"0 Years 0 Months 0 Weeks 0 Days 1 Hours 58 Minutes 1 Seconds",
    "locked":false,
    "length":55,
    "weight":"285672967",
    "minima":"1000000000",
    "coins":"2",
 ...
 ...
    "network":{
      "host":"172.20.0.2",
      "hostset":false,
      "port":9001,
      "connecting":0,
      "connected":10,
      "rpc":{
        "enabled":true,
        "port":9005
      },
      "p2p":{
        "address":"fda9:e0aa:589f:0:0:0:0:2:9001",
        "isAcceptingInLinks":true,
        "numInLinks":5,
        "numOutLinks":5,
        "numNotAcceptingConnP2PLinks":0,
        "numNoneP2PLinks":0,
        "numKnownPeers":2,
        "numUnvalidatedPeers":0,
        "numAllLinks":10,
        "nio_inbound":5,
        "nio_outbound":5
...
maxima
{
  "command":"maxima",
  "status":true,
  "pending":false,
  "response":{
    "name":"towelbyte_test_1",
    "icon":"0x00",
    "publickey":"0x30819F300D06092A864886F70D010101050003818D0030818902818100C0E6861B8B4FCDC924445AA9FA834727E188315DDB0C67FB17B8CF8D3F41C28231EFC85E2F19BF482834C063D4A706EA6EFD2F1BBEE0BC0AAEC7C4126FBF0E71FA4298E092D40332720530EE902D4204C11EACEE548AFA40A56D0005E7ADDAA8934A3A7618E57F12B8D10D66A495D4C4648B4FA341CA11251DE82403B9BFF3F90203010001",
    "staticmls":false,
    "mls":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G17877K1YKF3K5CV2FR7FM5ZM7HS0BD25018PEB4AFW37C6Q2EQT37WJ56PBKFYCY1QVZV294ST06T323CJ7RH2SQ2G8T5V7N8V0F2C53VPKJHPHHUN2YDR318EJ0ENN9YVZ9D2QBPAH89FM26JCMJYM8U8BWYRF8SQWPYGPKB425QBP88CBJPSFDRWF856Z7TDF9738M9KP3A410608004YVG9VM@fda9:e0aa:589f:0:0:0:0:3:9001",
    "localidentity":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G12CKF95HP9Q1SFEM5DFCE9BVCWGZQ6WZA2NDM2HHAH59CEA2VCHYDS6QCYZSDP175P15FB4CRB16MHK1YEU9ARST1C6VASB524HNEEZM45UGH17EZ5ZQ1FJ81RTH88GGN09RD73QDZSYFMRW594ZJ6F7KBZNNN6487YV18376PN0K89KJ9BQMCP03T1PU5DM7SFD9MQ12ETA0C10608006YF3AYF@172.20.0.2:9001",
    "p2pidentity":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G12CKF95HP9Q1SFEM5DFCE9BVCWGZQ6WZA2NDM2HHAH59CEA2VCHYDS6QCYZSDP175P15FB4CRB16MHK1YEU9ARST1C6VASB524HNEEZM45UGH17EZ5ZQ1FJ81RTH88GGN09RD73QDZSYFMRW594ZJ6F7KBZNNN6487YV18376PN0K89KJ9BQMCP03T1PU5DM7SFD9MQ12ETA0C10608006YF3AYF@fda9:e0aa:589f:0:0:0:0:2:9001",
    "contact":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G13P2JWVKB65Y6C9H4SCM03RY9DRFSBYDAVTRZ3286DRC6426MHAEZZ3GB8G23VCR5EWN82R22843R34056M06Z6BQEY6SJKYGEWZZ3J9T9WHFHSVNFBS222YA0QDAVYGGGNR4HSBNZ87JNHFAJ08ZQQVMP64M1GHHDSEHCEUZ110303NJBW1TUGD5D3CTK0Z5UD3QBSDVFZUUK10608006QWVV1A@fda9:e0aa:589f:0:0:0:0:4:9001",
    "logs":false,
    "poll":0
  }
}
maxcontacts
{
  "command":"maxcontacts",
  "status":true,
  "pending":false,
  "response":{
    "allowallcontacts":true,
    "contacts":[{
      "id":1,
      "publickey":"0x30819F300D06092A864886F70D010101050003818D00308189028181008A27FEE846DE496A82B6DDCADCD7DA8BD7A97AAF453D3A9C7BA8285EAE6A98A5ED3CCB2210021ADFFAF758A2DF2C2A3FE78A317FD447658233DFD3749B6A6A3D1999348349673B71B0F31EA9174CE261B41A55D8AC6582219D5A89429F608608C28AE884FD8942BCDA7EFA21C35E98F7D85B215A4FF25FA30A537EC52F9DA8050203010001",
      "currentaddress":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G17877K1YKF3K5CV2FR7FM5ZM7HS0BD25018PEB4AFW37C6Q2EQT37WJ56PBKFYCY1QVZV294ST06T323CJ7RH2SQ2G8T5V7N8V0F2C53VPKJHPHHUN2YDR318EJ0ENN9YVZ9D2QBPAH89FM26JCMJYM8U8BWYRF8SQWPYGPKB425QBP88CBJPSFDRWF856Z7TDF9738M9KP3A410608004YVG9VM@fda9:e0aa:589f:0:0:0:0:3:9001",
      "myaddress":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G13P2JWVKB65Y6C9H4SCM03RY9DRFSBYDAVTRZ3286DRC6426MHAEZZ3GB8G23VCR5EWN82R22843R34056M06Z6BQEY6SJKYGEWZZ3J9T9WHFHSVNFBS222YA0QDAVYGGGNR4HSBNZ87JNHFAJ08ZQQVMP64M1GHHDSEHCEUZ110303NJBW1TUGD5D3CTK0Z5UD3QBSDVFZUUK10608006QWVV1A@fda9:e0aa:589f:0:0:0:0:4:9001",
      "lastseen":1730907392814,
      "date":"Wed Nov 06 15:36:32 GMT 2024",
      "extradata":{
        "name":"towelbyte_test_2",
        "icon":"0x00",
        "minimaaddress":"MxG087Z13DVAGPTVVH99KQ0UAUM23QRHUKC4Z3W0WR3G7RR1ZC0MWWS8TF5EPYW",
        "topblock":"424",
        "checkblock":"408",
        "checkhash":"0x00000751E7420B35D79A46229B48BFF2A9695542DCDBFC4E88F69BA439FBD7EC",
        "mls":"MxG18HGG6FJ038614Y8CW46US6G20810K0070CD00Z83282G60G12CKF95HP9Q1SFEM5DFCE9BVCWGZQ6WZA2NDM2HHAH59CEA2VCHYDS6QCYZSDP175P15FB4CRB16MHK1YEU9ARST1C6VASB524HNEEZM45UGH17EZ5ZQ1FJ81RTH88GGN09RD73QDZSYFMRW594ZJ6F7KBZNNN6487YV18376PN0K89KJ9BQMCP03T1PU5DM7SFD9MQ12ETA0C10608006YF3AYF@fda9:e0aa:589f:0:0:0:0:2:9001"
      },
      "chaintip":"435",
      "samechain":true
    }]
  }
}
towelbyte commented 1 day ago

@spartacusrex99 @Jazminima For some reason I cannot add you as reviewers (maybe access rights thing?), thus tagging you here.

spartacusrex99 commented 11 hours ago

Thanks!

I'm having a play..

as we discussed the issue is whether to just switch to v6.. or use Both..