This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from ipfs/refactor
refactor: bubble swarm up and make a module just for it, preprepare libp2p to be used directly from libp2p instance, take off cat alias, make ping into its own module
- Loading branch information
Showing
22 changed files
with
155 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const Libp2pNode = require('libp2p-ipfs').Node | ||
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 Libp2pNode(self._peerInfo) | ||
self._libp2pNode.start(() => { | ||
// 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.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) | ||
}) | ||
}), | ||
stop: promisify((callback) => { | ||
self._libp2pNode.stop(callback) | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
|
||
module.exports = function ping (self) { | ||
return promisify((callback) => { | ||
callback(new Error('Not implemented')) | ||
}) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
const multiaddr = require('multiaddr') | ||
const promisify = require('promisify-es6') | ||
|
||
const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR | ||
|
||
module.exports = function swarm (self) { | ||
return { | ||
peers: promisify((callback) => { | ||
if (!self.isOnline()) { | ||
return callback(OFFLINE_ERROR) | ||
} | ||
|
||
const peers = self._libp2pNode.peerBook.getAll() | ||
const mas = [] | ||
Object | ||
.keys(peers) | ||
.forEach((b58Id) => { | ||
peers[b58Id].multiaddrs.forEach((ma) => { | ||
// TODO this should only print the addr we are using | ||
mas.push(ma) | ||
}) | ||
}) | ||
|
||
callback(null, mas) | ||
}), | ||
// all the addrs we know | ||
addrs: promisify((callback) => { | ||
if (!self.isOnline()) { | ||
return callback(OFFLINE_ERROR) | ||
} | ||
const peers = self._libp2pNode.peerBook.getAll() | ||
const mas = [] | ||
Object | ||
.keys(peers) | ||
.forEach((b58Id) => { | ||
peers[b58Id].multiaddrs.forEach((ma) => { | ||
// TODO this should only print the addr we are using | ||
mas.push(ma) | ||
}) | ||
}) | ||
|
||
callback(null, mas) | ||
}), | ||
localAddrs: promisify((callback) => { | ||
if (!self.isOnline()) { | ||
return callback(OFFLINE_ERROR) | ||
} | ||
|
||
callback(null, self._libp2pNode.peerInfo.multiaddrs) | ||
}), | ||
connect: promisify((maddr, callback) => { | ||
if (!self.isOnline()) { | ||
return callback(OFFLINE_ERROR) | ||
} | ||
|
||
if (typeof maddr === 'string') { | ||
maddr = multiaddr(maddr) | ||
} | ||
|
||
self._libp2pNode.dialByMultiaddr(maddr, callback) | ||
}), | ||
disconnect: promisify((maddr, callback) => { | ||
if (!self.isOnline()) { | ||
return callback(OFFLINE_ERROR) | ||
} | ||
|
||
if (typeof maddr === 'string') { | ||
maddr = multiaddr(maddr) | ||
} | ||
|
||
self._libp2pNode.hangUpByMultiaddr(maddr, callback) | ||
}), | ||
filters: promisify((callback) => { | ||
// TODO | ||
throw new Error('Not implemented') | ||
}) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.