Skip to content
This repository was archived by the owner on Mar 11, 2020. It is now read-only.

Commit 60277b1

Browse files
committed
chore: remove peerInfo from constructor
1 parent 33bf777 commit 60277b1

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/connection.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const { Duplex } = require('stream')
4-
53
const PeerInfo = require('peer-info')
64
const multiaddr = require('multiaddr')
75
const multistream = require('multistream-select')
@@ -21,17 +19,13 @@ const defaultMaxNumberOfAttemptsForHasMultiplexer = 5
2119
* This is an abstract duplex connection between two nodes and
2220
* each transport must pipe its socket through this.
2321
*/
24-
class Connection extends Duplex {
22+
class Connection {
2523
/**
2624
* Creates an instance of Connection.
27-
* @param {PeerInfo} peerInfo remote peer PeerInfo
2825
* @param {multiaddr} remoteMa remote peer multiaddr
2926
* @param {boolean} [isInitiator=true] peer initiated the connection
3027
*/
31-
constructor (peerInfo, remoteMa, isInitiator = true) {
32-
super()
33-
34-
assert(PeerInfo.isPeerInfo(peerInfo), 'peerInfo must be an instance of PeerInfo')
28+
constructor (remoteMa, isInitiator = true) {
3529
assert(multiaddr.isMultiaddr(remoteMa), 'remoteMa must be an instance of multiaddr')
3630
assert(typeof isInitiator === 'boolean', 'isInitiator must be a boolean')
3731

@@ -40,11 +34,6 @@ class Connection extends Duplex {
4034
*/
4135
this.id = (~~(Math.random() * 1e9)).toString(36) + Date.now()
4236

43-
/**
44-
* Remote peer infos
45-
*/
46-
this.peerInfo = peerInfo
47-
4837
/**
4938
* Status of the connection
5039
*/
@@ -71,6 +60,11 @@ class Connection extends Duplex {
7160
*/
7261
this.role = isInitiator ? ROLE.INITIATOR : ROLE.RESPONDER
7362

63+
/**
64+
* Remote peer infos
65+
*/
66+
this.peerInfo = undefined
67+
7468
/**
7569
* Reference of the multiplexer being used
7670
*/
@@ -114,6 +108,16 @@ class Connection extends Duplex {
114108
this.endpoints.local = ma
115109
}
116110

111+
/**
112+
* Set remote peer info.
113+
* @param {PeerInfo} peerInfo remote peer PeerInfo
114+
*/
115+
setPeerInfo (peerInfo) {
116+
assert(PeerInfo.isPeerInfo(peerInfo), 'peerInfo must be an instance of PeerInfo')
117+
118+
this.peerInfo = peerInfo
119+
}
120+
117121
/**
118122
* Create a new stream from this connection
119123
* @param {string} protocol intended protocol for the stream

0 commit comments

Comments
 (0)