This repository was 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
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 #490
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should make it more obvious for folks to understand why this pieces are all attached here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future: We should use a more explicit DI than just through an object with all the things. It will make it easier for people that want to have their light ipfs nodes to understand what are the dependencies of each component that IPFS uses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strongly agree with the
Note for the future