marcelklehr / smokesignal

Build your own small (or larger) peer to peer network with node.js
154 stars 21 forks source link

Issue with LocalHost node ? #20

Open sethleedy opened 7 years ago

sethleedy commented 7 years ago

I'm setting up the smoke p2p on multiple ip addresses on my machine(Ubuntu shell on Windows 10). I'm testing the connectivity with a localhost node. I'm getting this error concerning the netmask.js: /mnt/c/Users/Seth/Documents/Syncs/Research_and_Dev/Current Projects/P2P-Nodes/P2P-Nodes/node_modules/netmask/lib/netmask.js:23 throw new Error("Invalid byte: " + byte); ^

Error: Invalid byte: undefined at ip2long (/mnt/c/Users/Seth/Documents/Syncs/Research_and_Dev/Current Projects/P2P-Nodes/P2P-Nodes/node_modules/netmask/lib/netmask.js:23:15) at Netmask.contains (/mnt/c/Users/Seth/Documents/Syncs/Research_and_Dev/Current Projects/P2P-Nodes/P2P-Nodes/node_modules/netmask/lib/netmask.js:106:17) at Object.exports.localIp (/mnt/c/Users/Seth/Documents/Syncs/Research_and_Dev/Current Projects/P2P-Nodes/P2P-Nodes/node_modules/smokesignal/index.js:22:17) at Object.startupLocalSmoke (/mnt/c/Users/Seth/Documents/Syncs/Research_and_Dev/Current Projects/P2P-Nodes/P2P-Nodes/custom_modules/functions.js:25:28)

Code:

startupLocalSmoke: function(defaultSeeds = ["127.0.0.1", "13"]) {
        console.log("startupLocalSmoke: " + defaultSeeds[0])

        var localNode = smoke.createNode({
            port: parseInt(defaultSeeds[1]),
            address: smoke.localIp(defaultSeeds[0] + "/255.0.0.0") // Tell it your subnet and it'll figure out the right IP for you
                //,seeds: [{port: defaultSeeds[1], address:defaultSeeds[0]}] // the address of a seed (a known node)
        })
sethleedy commented 7 years ago

Looking in the netmask.js:

ip2long = function(ip) {
    var b, byte, i, j, len;
    b = (ip + '').split('.');
    if (b.length === 0 || b.length > 4) {
      throw new Error('Invalid IP');
    }
    for (i = j = 0, len = b.length; j < len; i = ++j) {
      byte = b[i];
      if (isNaN(parseInt(byte, 10))) {
        throw new Error("Invalid byte: " + byte);
      }
      if (byte < 0 || byte > 255) {
        throw new Error("Invalid byte: " + byte);
      }
    }
    return ((b[0] || 0) << 24 | (b[1] || 0) << 16 | (b[2] || 0) << 8 | (b[3] || 0)) >>> 0;
  };

It's looking for an invalid length ?

marcelklehr commented 7 years ago

Hey! Which node version are you using?

sethleedy commented 7 years ago

node -v v6.10.3

marcelklehr commented 7 years ago

Can you run node -e "console.log(require('os').networkInterfaces())" and post the results here? Alternatively, you could try to debug to determine what exactly gets passed to ip2long...

sethleedy commented 7 years ago
{ eth1:
   [ { address: '192.168.150.1',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '00:50:56:c0:00:01',
       internal: false },
     { address: 'fe80::28a7:7463:7034:bbea',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '00:50:56:c0:00:01',
       scopeid: 18,
       internal: false } ],
  eth2:
   [ { address: '192.168.124.1',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '00:50:56:c0:00:08',
       internal: false },
     { address: 'fe80::915:fea3:9c32:85dd',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '00:50:56:c0:00:08',
       scopeid: 2,
       internal: false } ],
  eth3:
   [ { address: '192.168.1.67',
       netmask: '255.255.254.0',
       family: 'IPv4',
       mac: 'ca:cf:3f:4b:76:ab',
       internal: false },
     { address: '2607:fcc8:6640:c100:5ab0:d59a:8f56:aa8a',
       netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
       family: 'IPv6',
       mac: 'ca:cf:3f:4b:76:ab',
       scopeid: 0,
       internal: false },
     { address: 'fe80::b4e7:e26:ca6b:899',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'ca:cf:3f:4b:76:ab',
       scopeid: 5,
       internal: false } ],
  lo:
   [ { address: '127.0.0.1',
       netmask: '255.0.0.0',
       family: 'IPv4',
       mac: '00:00:00:00:00:00',
       internal: true },
     { address: '::1',
       netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
       family: 'IPv6',
       mac: '00:00:00:00:00:00',
       scopeid: 0,
       internal: true } ],
  wifi0:
   [ { address: '192.168.0.231',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '34:23:87:f2:86:dd',
       internal: false },
     { address: '2607:fcc8:6640:c100:5451:7671:1478:8619',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '34:23:87:f2:86:dd',
       scopeid: 0,
       internal: false },
     { address: '2607:fcc8:6640:c100:fce3:a9c5:b071:3a6c',
       netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
       family: 'IPv6',
       mac: '34:23:87:f2:86:dd',
       scopeid: 0,
       internal: false },
     { address: 'fe80::5451:7671:1478:8619',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '34:23:87:f2:86:dd',
       scopeid: 3,
       internal: false } ],
  eth4:
   [ { address: '2001:0:9d38:953c:2000:baf8:b446:6560',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '00:00:00:00:00:00',
       scopeid: 0,
       internal: false },
     { address: 'fe80::2000:baf8:b446:6560',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '00:00:00:00:00:00',
       scopeid: 20,
       internal: false } ] }
marcelklehr commented 7 years ago

Looks fine to me, you'll probably need to debug after all...