hyperswarm
Advanced tools
Comparing version 4.3.5 to 4.3.6
16
index.js
@@ -201,7 +201,2 @@ const { EventEmitter } = require('events') | ||
const existing = this._allConnections.get(remotePublicKey) | ||
if (existing) { | ||
if (existing.isInitiator === true && isOpen(existing)) return true | ||
} | ||
const peerInfo = this.peers.get(b4a.toString(remotePublicKey, 'hex')) | ||
@@ -242,4 +237,8 @@ if (peerInfo && peerInfo.banned) return true | ||
const existing = this._allConnections.get(conn.remotePublicKey) | ||
if (existing) { | ||
if (existing.isInitiator && isOpen(existing)) { | ||
// if both connections are from the same peer, pick newest. otherwise tie break based on pub keys | ||
const keepNew = conn.isInitiator === existing.isInitiator || b4a.compare(conn.publicKey, conn.remotePublicKey) > 0 | ||
if (keepNew === false) { | ||
conn.on('error', noop) | ||
@@ -249,2 +248,3 @@ conn.destroy(new Error(ERR_DUPLICATE)) | ||
} | ||
existing.on('error', noop) | ||
@@ -434,5 +434,1 @@ existing.destroy(new Error(ERR_DUPLICATE)) | ||
} | ||
function isOpen (stream) { | ||
return !!stream.id | ||
} |
{ | ||
"name": "hyperswarm", | ||
"version": "4.3.5", | ||
"version": "4.3.6", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -30,3 +30,3 @@ "files": [ | ||
"type": "git", | ||
"url": "https://github.com/hyperswarm/hyperswarm.git" | ||
"url": "https://github.com/holepunchto/hyperswarm.git" | ||
}, | ||
@@ -40,5 +40,5 @@ "author": "Mathias Buus (@mafintosh)", | ||
"bugs": { | ||
"url": "https://github.com/hyperswarm/hyperswarm/issues" | ||
"url": "https://github.com/holepunchto/hyperswarm/issues" | ||
}, | ||
"homepage": "https://github.com/hyperswarm/hyperswarm" | ||
"homepage": "https://github.com/holepunchto/hyperswarm" | ||
} |
# hyperswarm | ||
### [See the full API docs at docs.holepunch.to](https://docs.holepunch.to/building-blocks/hyperswarm) | ||
A high-level API for finding and connecting to peers who are interested in a "topic." | ||
@@ -7,3 +9,3 @@ | ||
``` | ||
npm install hyperswarm@next | ||
npm install hyperswarm | ||
``` | ||
@@ -14,2 +16,3 @@ | ||
const Hyperswarm = require('hyperswarm') | ||
const swarm1 = new Hyperswarm() | ||
@@ -19,8 +22,9 @@ const swarm2 = new Hyperswarm() | ||
swarm1.on('connection', (conn, info) => { | ||
// swarm1 will receive server connections | ||
conn.write('this is a server connection') | ||
conn.end() | ||
// swarm1 will receive server connections | ||
conn.write('this is a server connection') | ||
conn.end() | ||
}) | ||
swarm2.on('connection', (conn, info) => { | ||
conn.on('data', data => console.log('client got message:', data.toString())) | ||
conn.on('data', data => console.log('client got message:', data.toString())) | ||
}) | ||
@@ -56,6 +60,6 @@ | ||
See the [`PeerInfo`](https://github.com/hyperswarm/hyperswarm/blob/v3/README.md#peerinfo-api) API for more details. | ||
See the [`PeerInfo`](https://github.com/holepunchto/hyperswarm/blob/v3/README.md#peerinfo-api) API for more details. | ||
#### `swarm.dht` | ||
A [`@hyperswarm/dht`](https://github.com/hyperswarm/dht) instance. Useful if you want lower-level control over Hyperswarm's networking. | ||
A [`@hyperswarm/dht`](https://github.com/holepunchto/hyperswarm-dht) instance. Useful if you want lower-level control over Hyperswarm's networking. | ||
@@ -67,3 +71,3 @@ #### `swarm.on('connection', (socket, peerInfo) => {})` | ||
`peerInfo` is a [`PeerInfo`](https://github.com/hyperswarm/hyperswarm/blob/v3/README.md#peerinfo-api) instance | ||
`peerInfo` is a [`PeerInfo`](https://github.com/holepunchto/hyperswarm/blob/v3/README.md#peerinfo-api) instance | ||
@@ -78,3 +82,3 @@ #### `const discovery = swarm.join(topic, opts = {})` | ||
Returns a [`PeerDiscovery`](https://github.com/hyperswarm/hyperswarm/blob/v3/README.md#peerdiscovery-api) object. | ||
Returns a [`PeerDiscovery`](https://github.com/holepunchto/hyperswarm/blob/v3/README.md#peerdiscovery-api) object. | ||
@@ -112,3 +116,3 @@ #### Clients and Servers | ||
#### `const discovery = swarm.status(topic)` | ||
Get the [`PeerDiscovery`](https://github.com/hyperswarm/hyperswarm/blob/v3/README.md#peerdiscovery-api) object associated with the topic, if it exists. | ||
Get the [`PeerDiscovery`](https://github.com/holepunchto/hyperswarm/blob/v3/README.md#peerdiscovery-api) object associated with the topic, if it exists. | ||
@@ -115,0 +119,0 @@ #### `await swarm.listen()` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33819
157
740