@leofcoin/peernet 0.8.5 → 0.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,15 +69,16 @@ globalThis.pubsub = globalThis.pubsub || new PubSub({verbose: false});
69
69
  class PeernetClient {
70
70
  constructor(options = {}) {
71
71
  if (!options.id) options.id = Buffer.from('00000000000000000000000000000000');
72
-
72
+ if (!options.networkVersion) options.networkVersion = 'v0.1.0';
73
+ if (!options.networkName) options.networkName = 'peernet';
73
74
  this.id = options.id;
74
75
 
75
- this.topic = Buffer.from(sha256('peernet-v0.1.0').toString());
76
+ this.topic = Buffer.from(sha256(`${option.networkName}-${options.networkVersion}`).toString());
76
77
 
77
78
  const trackers = [
78
79
  'wss://star.leofcoin.org:7575',
79
80
  'wss://tracker.openwebtorrent.com',
80
- 'wss://tracker.sloppyta.co:443/announce',
81
+ // 'wss://tracker.sloppyta.co:443/announce',
81
82
  ];
82
83
  this.p2p = new P2P(trackers, this.topic.slice(0, 20));
83
84
  this.p2p.on('peerconnect', (peer) => {
@@ -87,77 +88,13 @@ class PeernetClient {
87
88
  });
88
89
 
89
90
  this.p2p.on('peerclose', (peer) => {
91
+ // TODO: close peernetPeer
90
92
  connections.delete(peer.id);
91
93
  pubsub.publish('peer:disconnected', peer);
92
94
  });
93
95
 
94
96
  this.p2p.start();
95
97
 
96
-
97
- // this.sw.join(this.topic.slice(0, 32))
98
- //
99
- // const arrayOfPeers = this.sw.getPeers()
100
- //
101
- // this.sw.on('connection', async (connection, info) => {
102
- // // connected
103
- // const id = info.id.toString()
104
- // if (id === this.id.toString()) return
105
- //
106
- // const channel = connection.channelName
107
- // let channels = [channel]
108
- // let peer
109
- // if (connections.has(id)) {
110
- // const value = connections.get(id)
111
- // const _channels = value.channels
112
- // channels = [...channels, ..._channels]
113
- // peer = value.peer
114
- // } else {
115
- // peer = new PeernetPeer(id, connection)
116
- // pubsub.publish('peer:connected', peer)
117
- // }
118
- // connections.set(id, {channels, peer})
119
- // // connection.on('data', (data) => console.log({data}))
120
- // // connection.write('peerId')
121
- // });
122
- //
123
- // this.sw.on('candidates-updated', async (channel, candidates) => {
124
- // // TODO: Channels ...
125
- // for (const candidate of candidates) {
126
- // const id = candidate.toString()
127
- // let channels = [channel]
128
- // if (id === this.id.toString()) return
129
- //
130
- // if (!connections.has(id)) {
131
- // try {
132
- // const connection = await this.sw.connect(channel, candidate)
133
- // const peer = new PeernetPeer(id, connection)
134
- // connections.set(id, {channels, peer})
135
- // if (recentConnections.has(id)) {
136
- // setTimeout(() => {
137
- // pubsub.publish('peer:connected', peer)
138
- // }, 1000)
139
- // } else {
140
- // pubsub.publish('peer:connected', peer)
141
- // }
142
- // } catch (e) {
143
- // console.warn(e);
144
- // }
145
- // } else {
146
- // const value = connections.get(id)
147
- // const _channels = value.channels
148
- // channels = [...channels, ..._channels]
149
- // connections.set(id, {channels, peer: value.peer})
150
- // }
151
- // }
152
- // })
153
- //
154
- // this.sw.on('connection-closed', (connection, info) => {
155
- // if (!recentConnections.has(info.id.toString())) {
156
- // recentConnections.set(info.id.toString(), new Date().getTime())
157
- // }
158
- // if (connections.has(info.id.toString())) connections.delete(info.id.toString())
159
- // })
160
- //
161
98
  if (globalThis.process) {
162
99
  process.on('SIGINT', async () => {
163
100
  console.log('Caught interrupt signal');
@@ -307,7 +244,7 @@ class LeofcoinStorage$1 {
307
244
 
308
245
  }
309
246
 
310
- var version = "0.8.4";
247
+ var version = "0.8.9";
311
248
 
312
249
  var api$1 = {
313
250
  version: ({send}) => send({client: '@peernet/api/http', version}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.8.5",
3
+ "version": "0.8.9",
4
4
  "description": "",
5
5
  "main": "dist/commonjs/peernet.js",
6
6
  "module": "dist/module/peernet.js",