Skip to content

Commit

Permalink
add preferredPort (default 13331) to core opts
Browse files Browse the repository at this point in the history
add a preferredPort to listen for hyperswarm connections on. the
preferredPort is smart enough that if it is blocked, hyperswarm will try
preferredPort+1, preferredPort+2 before giving up. see the hyperswarm code:
https://github.com/hyperswarm/network/blob/ad41b0c2ac19dbf92865e481282ba6ac6e513d57/index.js#L150-L162

this allows people with highly configured firewalls to port forward a
single port for cabal, which they can themselves configure in their
clients.

fix #98
  • Loading branch information
cblgh committed Jan 11, 2021
1 parent 2f41eb5 commit b8185e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Cabal (storage, key, opts) {
this.maxFeeds = opts.maxFeeds
this.modKeys = opts.modKeys || []
this.adminKeys = opts.adminKeys || []
this.preferredPort = opts.preferredPort || 13331

if (!key) this.key = generateKeyHex()
else {
Expand Down
3 changes: 2 additions & 1 deletion swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = function (cabal, opts, cb) {

const discoveryKey = crypto.discoveryKey(Buffer.from(cabal.key, 'hex'))

const swarm = hyperswarm()
const { preferredPort } = cabal
const swarm = hyperswarm({ preferredPort })
swarm.join(discoveryKey, {
lookup: true,
announce: true
Expand Down

0 comments on commit b8185e5

Please sign in to comment.