From 1ec48066c12a3881af7c755e981cf82bdef67418 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 11 Dec 2016 18:35:04 -0800 Subject: [PATCH] feat: add multicastdns to the mix --- package.json | 12 +++--- src/core/components/libp2p.js | 39 ++++++++++++-------- test/core/node-only/test-init.js | 3 +- test/go-ipfs-repo/config | 2 +- test/http-api/custom-ipfs-api/test-config.js | 3 +- test/test-data/otherconfig | 2 +- test/utils/factory-core/default-config.json | 2 +- test/utils/factory-http/default-config.json | 2 +- test/utils/temp-node.js | 4 ++ 9 files changed, 42 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 797d5a7eff..0ad11e2d54 100644 --- a/package.json +++ b/package.json @@ -60,12 +60,12 @@ "form-data": "^2.1.2", "fs-pull-blob-store": "^0.4.1", "gulp": "^3.9.1", - "interface-ipfs-core": "^0.22.0", + "interface-ipfs-core": "^0.22.1", "left-pad": "^1.1.3", "lodash": "^4.17.2", "ncp": "^2.0.0", "nexpect": "^0.5.0", - "pre-commit": "^1.2.0", + "pre-commit": "^1.2.1", "rimraf": "^2.5.4", "stream-to-promise": "^2.2.0", "transform-loader": "^0.2.3" @@ -82,7 +82,7 @@ "idb-pull-blob-store": "^0.5.1", "ipfs-api": "^12.0.3", "ipfs-bitswap": "^0.8.2", - "ipfs-block": "^0.5.1", + "ipfs-block": "^0.5.3", "ipfs-block-service": "^0.7.1", "ipfs-multipart": "^0.1.0", "ipfs-repo": "^0.11.1", @@ -91,8 +91,8 @@ "ipld-resolver": "^0.4.0", "isstream": "^0.1.2", "joi": "^10.0.5", - "libp2p-ipfs-nodejs": "^0.16.4", - "libp2p-ipfs-browser": "^0.17.1", + "libp2p-ipfs-nodejs": "^0.17.0", + "libp2p-ipfs-browser": "^0.17.2", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.has": "^4.5.2", @@ -150,4 +150,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index f6385992bf..158940e320 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -4,28 +4,37 @@ const Node = require('libp2p-ipfs-nodejs') const promisify = require('promisify-es6') module.exports = function libp2p (self) { - // TODO Just expose libp2p API directly, this start stop wrapping doesn't make that much sense anymore :) return { start: promisify((callback) => { - self._libp2pNode = new Node(self._peerInfo) - self._libp2pNode.start((err) => { + self.config.get('Discovery.MDNS.Enabled', (err, enabled) => { if (err) { return callback(err) } + const options = { + mdns: enabled + } - // TODO connect to bootstrap nodes, it will get us more addrs - self._libp2pNode.peerInfo.multiaddrs.forEach((ma) => { - console.log('Swarm listening on', ma.toString()) - }) - callback() - }) + self._libp2pNode = new Node(self._peerInfo, undefined, options) - self._libp2pNode.discovery.on('peer', (peerInfo) => { - self._libp2pNode.peerBook.put(peerInfo) - self._libp2pNode.dialByPeerInfo(peerInfo, () => {}) - }) - self._libp2pNode.swarm.on('peer-mux-established', (peerInfo) => { - self._libp2pNode.peerBook.put(peerInfo) + self._libp2pNode.start((err) => { + if (err) { + return callback(err) + } + + self._libp2pNode.peerInfo.multiaddrs.forEach((ma) => { + console.log('Swarm listening on', ma.toString()) + }) + + self._libp2pNode.discovery.on('peer', (peerInfo) => { + self._libp2pNode.peerBook.put(peerInfo) + self._libp2pNode.dialByPeerInfo(peerInfo, () => {}) + }) + self._libp2pNode.swarm.on('peer-mux-established', (peerInfo) => { + self._libp2pNode.peerBook.put(peerInfo) + }) + + callback() + }) }) }), stop: promisify((callback) => { diff --git a/test/core/node-only/test-init.js b/test/core/node-only/test-init.js index 6fcb7782fc..918abf27ff 100644 --- a/test/core/node-only/test-init.js +++ b/test/core/node-only/test-init.js @@ -23,7 +23,8 @@ describe('init (Node.js specific)', () => { it('init docs are written', (done) => { ipfs.init({ bits: 1024 }, (err) => { expect(err).to.not.exist - var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') + const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') + setTimeout(() => { ipfs.object.get(multihash, {}, (err, node) => { expect(err).to.not.exist diff --git a/test/go-ipfs-repo/config b/test/go-ipfs-repo/config index 5c7400e2fa..7a65038515 100644 --- a/test/go-ipfs-repo/config +++ b/test/go-ipfs-repo/config @@ -1 +1 @@ -{"Identity":{"PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A","PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="},"Datastore":{"Type":"","Path":"","StorageMax":"","StorageGCWatermark":0,"GCPeriod":"","Params":null,"NoSync":false},"Addresses":{"Swarm":["/ip4/127.0.0.1/tcp/9999", "/ip4/127.0.0.1/tcp/9990/ws"],"API":"/ip4/127.0.0.1/tcp/6001","Gateway":"/ip4/127.0.0.1/tcp/0"},"Mounts":{"IPFS":"/ipfs","IPNS":"/ipns","FuseAllowOther":false},"Version":{"Current":"0.4.0-dev","Check":"error","CheckDate":"0001-01-01T00:00:00Z","CheckPeriod":"172800000000000","AutoUpdate":"minor"},"Discovery":{"MDNS":{"Enabled":true,"Interval":10}},"Ipns":{"RepublishPeriod":"","RecordLifetime":"","ResolveCacheSize":128},"Bootstrap":["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ","/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z","/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM","/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm","/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu","/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64","/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd","/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3","/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"],"Tour":{"Last":""},"Gateway":{"HTTPHeaders":null,"RootRedirect":"","Writable":false},"SupernodeRouting":{"Servers":["/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U","/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6","/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH","/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP","/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R","/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4","/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v","/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"]},"API":{"HTTPHeaders":null},"Swarm":{"AddrFilters":null},"Log":{"MaxSizeMB":250,"MaxBackups":1,"MaxAgeDays":0}} +{"Identity":{"PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A","PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="},"Datastore":{"Type":"","Path":"","StorageMax":"","StorageGCWatermark":0,"GCPeriod":"","Params":null,"NoSync":false},"Addresses":{"Swarm":["/ip4/127.0.0.1/tcp/9999", "/ip4/127.0.0.1/tcp/9990/ws"],"API":"/ip4/127.0.0.1/tcp/6001","Gateway":"/ip4/127.0.0.1/tcp/0"},"Mounts":{"IPFS":"/ipfs","IPNS":"/ipns","FuseAllowOther":false},"Version":{"Current":"0.4.0-dev","Check":"error","CheckDate":"0001-01-01T00:00:00Z","CheckPeriod":"172800000000000","AutoUpdate":"minor"},"Discovery":{"MDNS":{"Enabled":false,"Interval":10}},"Ipns":{"RepublishPeriod":"","RecordLifetime":"","ResolveCacheSize":128},"Bootstrap":["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ","/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z","/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM","/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm","/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu","/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64","/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd","/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3","/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"],"Tour":{"Last":""},"Gateway":{"HTTPHeaders":null,"RootRedirect":"","Writable":false},"SupernodeRouting":{"Servers":["/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U","/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6","/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH","/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP","/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R","/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4","/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v","/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"]},"API":{"HTTPHeaders":null},"Swarm":{"AddrFilters":null},"Log":{"MaxSizeMB":250,"MaxBackups":1,"MaxAgeDays":0}} diff --git a/test/http-api/custom-ipfs-api/test-config.js b/test/http-api/custom-ipfs-api/test-config.js index 1966572141..c4c3d62433 100644 --- a/test/http-api/custom-ipfs-api/test-config.js +++ b/test/http-api/custom-ipfs-api/test-config.js @@ -8,6 +8,7 @@ const path = require('path') module.exports = (ctl) => { describe('.config', () => { const configPath = path.join(__dirname, '../../repo-tests-run/config') + let updatedConfig before(() => { @@ -66,7 +67,7 @@ module.exports = (ctl) => { }) // This one is one stale mode till go-ipfs decides - // what to do + // what to do with the .replace command describe('.replace', () => { it('returns error if the config is invalid', (done) => { const filePath = 'test/test-data/badconfig' diff --git a/test/test-data/otherconfig b/test/test-data/otherconfig index 870bb826f0..29978e4f8c 100644 --- a/test/test-data/otherconfig +++ b/test/test-data/otherconfig @@ -31,7 +31,7 @@ }, "Discovery": { "MDNS": { - "Enabled": true, + "Enabled": false, "Interval": 10 } }, diff --git a/test/utils/factory-core/default-config.json b/test/utils/factory-core/default-config.json index 20e1d1b753..adaa4113e6 100644 --- a/test/utils/factory-core/default-config.json +++ b/test/utils/factory-core/default-config.json @@ -33,7 +33,7 @@ }, "Discovery": { "MDNS": { - "Enabled": true, + "Enabled": false, "Interval": 10 } }, diff --git a/test/utils/factory-http/default-config.json b/test/utils/factory-http/default-config.json index 20e1d1b753..adaa4113e6 100644 --- a/test/utils/factory-http/default-config.json +++ b/test/utils/factory-http/default-config.json @@ -33,7 +33,7 @@ }, "Discovery": { "MDNS": { - "Enabled": true, + "Enabled": false, "Interval": 10 } }, diff --git a/test/utils/temp-node.js b/test/utils/temp-node.js index 405503d048..a61fa2a201 100644 --- a/test/utils/temp-node.js +++ b/test/utils/temp-node.js @@ -12,6 +12,7 @@ function setAddresses (repo, num, callback) { if (err) { return callback(err) } + config.Addresses = { Swarm: [ `/ip4/127.0.0.1/tcp/10${num}`, @@ -20,6 +21,9 @@ function setAddresses (repo, num, callback) { API: `/ip4/127.0.0.1/tcp/31${num}`, Gateway: `/ip4/127.0.0.1/tcp/32${num}` } + + config.Discovery.MDNS.Enabled = false + repo.config.set(config, callback) }) }