@leofcoin/peernet 1.1.58 → 1.1.60
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.
- package/.prettierrc +7 -0
- package/.travis.yml +4 -4
- package/exports/browser/browser-store.js +1 -1
- package/exports/browser/{index-8868bdd8.js → index-5cd0a662.js} +1 -1
- package/exports/browser/{messages-eb6e5c71.js → messages-638774c5.js} +15 -25
- package/exports/browser/{peernet-87ea02a4.js → peernet-61545c25.js} +7165 -292
- package/exports/browser/peernet.d.ts +13 -16
- package/exports/browser/peernet.js +1 -1
- package/exports/browser/types.d.ts +5 -5
- package/exports/{messages-b9a32987.js → messages-42b2109e.js} +14 -24
- package/exports/peernet.js +110 -132
- package/exports/src/prompts/password.js +1 -1
- package/exports/store.js +3 -1
- package/exports/types/peernet.d.ts +13 -16
- package/exports/types/types.d.ts +5 -5
- package/package.json +1 -1
- package/src/dht/dht.ts +39 -33
- package/src/discovery/peer-discovery.js +8 -8
- package/src/handlers/data.js +3 -3
- package/src/handlers/message.js +1 -1
- package/src/identity.ts +12 -11
- package/src/messages/chat.js +1 -2
- package/src/messages/data-response.js +1 -2
- package/src/messages/data.js +1 -2
- package/src/messages/dht-response.js +1 -2
- package/src/messages/dht.js +1 -2
- package/src/messages/file-link.js +1 -2
- package/src/messages/file.js +1 -2
- package/src/messages/peer-response.js +1 -2
- package/src/messages/peer.js +1 -1
- package/src/messages/peernet.js +1 -2
- package/src/messages/ps.js +1 -1
- package/src/messages/request.js +1 -2
- package/src/messages/response.js +1 -2
- package/src/peernet.ts +333 -394
- package/src/prompts/password/browser.js +1 -1
- package/src/prompts/password/node.js +2 -2
- package/src/proto/chat-message.proto.js +1 -1
- package/src/proto/data-response.proto.js +1 -1
- package/src/types.ts +7 -9
- package/src/utils/utils.js +7 -8
- package/exports/browser/identity.d.ts +0 -18
- package/exports/types/identity.d.ts +0 -18
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import
|
|
3
|
-
import PubSub from
|
|
4
|
-
import PeerDiscovery from
|
|
5
|
-
import DHT from
|
|
6
|
-
import MessageHandler from
|
|
7
|
-
import LeofcoinStorageClass from
|
|
8
|
-
import Identity from
|
|
9
|
-
import swarm from
|
|
10
|
-
import P2PTPeer from "@netpeer/p2pt-swarm/peer";
|
|
2
|
+
import '@vandeurenglenn/debug';
|
|
3
|
+
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
4
|
+
import PeerDiscovery from './discovery/peer-discovery.js';
|
|
5
|
+
import DHT from './dht/dht.js';
|
|
6
|
+
import MessageHandler from './handlers/message.js';
|
|
7
|
+
import { Storage as LeofcoinStorageClass } from '@leofcoin/storage';
|
|
8
|
+
import Identity from './identity.js';
|
|
9
|
+
import swarm from '@netpeer/p2pt-swarm';
|
|
11
10
|
declare global {
|
|
12
11
|
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
13
12
|
var peernet: Peernet;
|
|
@@ -68,9 +67,7 @@ export default class Peernet {
|
|
|
68
67
|
constructor(options: any, password: any);
|
|
69
68
|
get id(): string;
|
|
70
69
|
get selectedAccount(): string;
|
|
71
|
-
get accounts(): Promise<[
|
|
72
|
-
[name: string, externalAddress: string, internalAddress: string]
|
|
73
|
-
]>;
|
|
70
|
+
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
74
71
|
get defaultStores(): string[];
|
|
75
72
|
selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
|
|
76
73
|
addProto(name: any, proto: any): void;
|
|
@@ -85,13 +82,13 @@ export default class Peernet {
|
|
|
85
82
|
*
|
|
86
83
|
* @return {Array} peerId
|
|
87
84
|
*/
|
|
88
|
-
get peers(): [string,
|
|
89
|
-
get connections():
|
|
90
|
-
get peerEntries():
|
|
85
|
+
get peers(): [string, unknown][];
|
|
86
|
+
get connections(): unknown[];
|
|
87
|
+
get peerEntries(): unknown[];
|
|
91
88
|
/**
|
|
92
89
|
* @return {String} id - peerId
|
|
93
90
|
*/
|
|
94
|
-
getConnection(id: any):
|
|
91
|
+
getConnection(id: any): unknown;
|
|
95
92
|
/**
|
|
96
93
|
* @private
|
|
97
94
|
*
|
package/exports/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '@vandeurenglenn/debug';
|
|
2
2
|
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
3
3
|
import Peernet from './peernet.js';
|
|
4
|
-
import {
|
|
4
|
+
import { Storage as LeofcoinStorageClass } from '@leofcoin/storage';
|
|
5
5
|
declare global {
|
|
6
6
|
var debug: (message: any) => string;
|
|
7
7
|
var globalSub: PubSub;
|
|
@@ -9,8 +9,8 @@ declare global {
|
|
|
9
9
|
var peernet: Peernet;
|
|
10
10
|
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
11
11
|
var LeofcoinStorageClient: any;
|
|
12
|
-
var messageStore:
|
|
13
|
-
var dataStore:
|
|
14
|
-
var transactionStore:
|
|
15
|
-
var blockStore:
|
|
12
|
+
var messageStore: LeofcoinStorageClass;
|
|
13
|
+
var dataStore: LeofcoinStorageClass;
|
|
14
|
+
var transactionStore: LeofcoinStorageClass;
|
|
15
|
+
var blockStore: LeofcoinStorageClass;
|
|
16
16
|
}
|
package/package.json
CHANGED
package/src/dht/dht.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export declare type DHTProvider = {
|
|
2
|
-
address: string
|
|
2
|
+
address: string
|
|
3
3
|
id: string
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export declare type DHTProviderDistanceResult = {
|
|
7
|
-
provider: DHTProvider
|
|
7
|
+
provider: DHTProvider
|
|
8
8
|
/**
|
|
9
9
|
* distance on earth between peers in km
|
|
10
10
|
*/
|
|
11
11
|
distance: number
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export declare type DHTProviderMapValue = {[index: string]: DHTProvider}
|
|
14
|
+
export declare type DHTProviderMapValue = { [index: string]: DHTProvider }
|
|
15
15
|
|
|
16
16
|
declare type Coordinates = {
|
|
17
|
-
longitude: number
|
|
17
|
+
longitude: number
|
|
18
18
|
latitude: number
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -26,62 +26,62 @@ declare type Coordinates = {
|
|
|
26
26
|
const lastFetched = {
|
|
27
27
|
address: {
|
|
28
28
|
value: undefined,
|
|
29
|
-
timestamp: 0
|
|
29
|
+
timestamp: 0
|
|
30
30
|
},
|
|
31
31
|
ptr: {
|
|
32
32
|
value: undefined,
|
|
33
|
-
timestamp: 0
|
|
34
|
-
}
|
|
33
|
+
timestamp: 0
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const fetchedCoordinates = {}
|
|
38
38
|
|
|
39
39
|
const getAddress = async () => {
|
|
40
|
-
const {address} = lastFetched
|
|
40
|
+
const { address } = lastFetched
|
|
41
41
|
if (address) {
|
|
42
42
|
address.value = await fetch('https://icanhazip.com/')
|
|
43
43
|
address.value = await address.value.text()
|
|
44
|
-
address.timestamp = Math.round(new Date().getTime() / 1000)
|
|
45
|
-
lastFetched.address = address
|
|
44
|
+
address.timestamp = Math.round(new Date().getTime() / 1000)
|
|
45
|
+
lastFetched.address = address
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return address.value
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const degreesToRadians = (degrees) => {
|
|
52
|
-
return degrees * Math.PI / 180
|
|
52
|
+
return (degrees * Math.PI) / 180
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
|
|
56
|
-
const earthRadiusKm = 6371
|
|
56
|
+
const earthRadiusKm = 6371
|
|
57
57
|
|
|
58
|
-
const dLat = degreesToRadians(lat2-lat1)
|
|
59
|
-
const dLon = degreesToRadians(lon2-lon1)
|
|
58
|
+
const dLat = degreesToRadians(lat2 - lat1)
|
|
59
|
+
const dLon = degreesToRadians(lon2 - lon1)
|
|
60
60
|
|
|
61
|
-
lat1 = degreesToRadians(lat1)
|
|
62
|
-
lat2 = degreesToRadians(lat2)
|
|
63
|
-
const a =
|
|
64
|
-
|
|
65
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
|
|
66
|
-
return earthRadiusKm * c
|
|
61
|
+
lat1 = degreesToRadians(lat1)
|
|
62
|
+
lat2 = degreesToRadians(lat2)
|
|
63
|
+
const a =
|
|
64
|
+
Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2)
|
|
65
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
66
|
+
return earthRadiusKm * c
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export default class DhtEarth {
|
|
70
|
-
providerMap = new Map<string, DHTProviderMapValue>
|
|
70
|
+
providerMap = new Map<string, DHTProviderMapValue>()
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
*
|
|
74
74
|
*/
|
|
75
75
|
constructor() {
|
|
76
|
-
this.providerMap = new Map()
|
|
76
|
+
this.providerMap = new Map()
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
async getCoordinates(address: string): Promise<Coordinates> {
|
|
80
80
|
if (!fetchedCoordinates[address]) {
|
|
81
81
|
const request = `https://whereis.leofcoin.org/?ip=${address}`
|
|
82
82
|
let response = await fetch(request)
|
|
83
|
-
const {lat, lon} = await response.json() as { lat: number
|
|
84
|
-
fetchedCoordinates[address] = {latitude: lat, longitude: lon}
|
|
83
|
+
const { lat, lon } = (await response.json()) as { lat: number; lon: number }
|
|
84
|
+
fetchedCoordinates[address] = { latitude: lat, longitude: lon }
|
|
85
85
|
}
|
|
86
86
|
return fetchedCoordinates[address]
|
|
87
87
|
}
|
|
@@ -91,25 +91,31 @@ export default class DhtEarth {
|
|
|
91
91
|
* @param {Object} provider
|
|
92
92
|
* @return {Object} {provider, distance}
|
|
93
93
|
*/
|
|
94
|
-
async getDistance(
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
async getDistance(
|
|
95
|
+
peer: { latitude: number; longitude: number },
|
|
96
|
+
provider: DHTProvider
|
|
97
|
+
): Promise<DHTProviderDistanceResult> {
|
|
98
|
+
const { latitude, longitude } = await this.getCoordinates(provider.address)
|
|
99
|
+
return {
|
|
100
|
+
provider,
|
|
101
|
+
distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude)
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
async closestPeer(providers: Array<any>): Promise<DHTProvider> {
|
|
100
106
|
let all = []
|
|
101
|
-
const address = await getAddress()
|
|
107
|
+
const address = await getAddress()
|
|
102
108
|
const peerLoc = await this.getCoordinates(address)
|
|
103
109
|
|
|
104
110
|
for (const provider of providers) {
|
|
105
|
-
if (provider.address === '127.0.0.1' || provider.address === '::1') all.push({provider, distance: 0})
|
|
111
|
+
if (provider.address === '127.0.0.1' || provider.address === '::1') all.push({ provider, distance: 0 })
|
|
106
112
|
else all.push(this.getDistance(peerLoc, provider))
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
// todo queue
|
|
110
|
-
all = await Promise.all(all)
|
|
116
|
+
all = await Promise.all(all)
|
|
111
117
|
all = all.sort((previous, current) => previous.distance - current.distance)
|
|
112
|
-
return all[0].provider
|
|
118
|
+
return all[0].provider
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
hasProvider(hash: string): boolean {
|
|
@@ -117,7 +123,7 @@ export default class DhtEarth {
|
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
providersFor(hash: string): DHTProviderMapValue {
|
|
120
|
-
let providers:
|
|
126
|
+
let providers: DHTProviderMapValue
|
|
121
127
|
if (this.providerMap.has(hash)) providers = this.providerMap.get(hash)
|
|
122
128
|
return providers
|
|
123
129
|
}
|
|
@@ -131,7 +137,7 @@ export default class DhtEarth {
|
|
|
131
137
|
this.providerMap.set(hash, providers)
|
|
132
138
|
}
|
|
133
139
|
|
|
134
|
-
removeProvider(address: string, hash: string){
|
|
140
|
+
removeProvider(address: string, hash: string) {
|
|
135
141
|
if (this.providerMap.has(hash)) {
|
|
136
142
|
const providers = this.providerMap.get(hash)
|
|
137
143
|
delete providers[address]
|
|
@@ -6,7 +6,7 @@ export default class PeerDiscovery {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
_getPeerId(id) {
|
|
9
|
-
if (!peernet.peerMap || peernet.peerMap && peernet.peerMap.size === 0) return false
|
|
9
|
+
if (!peernet.peerMap || (peernet.peerMap && peernet.peerMap.size === 0)) return false
|
|
10
10
|
|
|
11
11
|
for (const entry of [...peernet.peerMap.entries()]) {
|
|
12
12
|
for (const _id of entry[1]) {
|
|
@@ -18,7 +18,7 @@ export default class PeerDiscovery {
|
|
|
18
18
|
async discover(peer) {
|
|
19
19
|
let id = this._getPeerId(peer.id)
|
|
20
20
|
if (id) return id
|
|
21
|
-
const data = await new peernet.protos['peernet-peer']({id: this.id})
|
|
21
|
+
const data = await new peernet.protos['peernet-peer']({ id: this.id })
|
|
22
22
|
const node = await peernet.prepareMessage(peer.id, data.encoded)
|
|
23
23
|
|
|
24
24
|
let response = await peer.request(node.encoded)
|
|
@@ -26,7 +26,7 @@ export default class PeerDiscovery {
|
|
|
26
26
|
response = await new peernet.protos['peernet-peer-response'](response.decoded.data)
|
|
27
27
|
|
|
28
28
|
id = response.decoded.id
|
|
29
|
-
if (id === this.id) return
|
|
29
|
+
if (id === this.id) return
|
|
30
30
|
|
|
31
31
|
if (!peernet.peerMap.has(id)) peernet.peerMap.set(id, [peer.id])
|
|
32
32
|
else {
|
|
@@ -40,11 +40,11 @@ export default class PeerDiscovery {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
async discoverHandler(message, peer) {
|
|
43
|
-
const {id, proto} = message
|
|
43
|
+
const { id, proto } = message
|
|
44
44
|
// if (typeof message.data === 'string') message.data = Buffer.from(message.data)
|
|
45
45
|
if (proto.name === 'peernet-peer') {
|
|
46
46
|
const from = proto.decoded.id
|
|
47
|
-
if (from === this.id) return
|
|
47
|
+
if (from === this.id) return
|
|
48
48
|
|
|
49
49
|
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id])
|
|
50
50
|
else {
|
|
@@ -54,13 +54,13 @@ export default class PeerDiscovery {
|
|
|
54
54
|
peernet.peerMap.set(from, connections)
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
const data = await new peernet.protos['peernet-peer-response']({id: this.id})
|
|
57
|
+
const data = await new peernet.protos['peernet-peer-response']({ id: this.id })
|
|
58
58
|
const node = await peernet.prepareMessage(from, data.encoded)
|
|
59
59
|
|
|
60
|
-
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
|
|
60
|
+
peer.write(Buffer.from(JSON.stringify({ id, data: node.encoded })))
|
|
61
61
|
} else if (proto.name === 'peernet-peer-response') {
|
|
62
62
|
const from = proto.decoded.id
|
|
63
|
-
if (from === this.id) return
|
|
63
|
+
if (from === this.id) return
|
|
64
64
|
|
|
65
65
|
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id])
|
|
66
66
|
else {
|
package/src/handlers/data.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { protoFor } from './../utils/utils.js'
|
|
2
2
|
|
|
3
|
-
const dataHandler = async message => {
|
|
3
|
+
const dataHandler = async (message) => {
|
|
4
4
|
if (!message) return
|
|
5
5
|
|
|
6
|
-
const {data, id, from, peer} = message
|
|
6
|
+
const { data, id, from, peer } = message
|
|
7
7
|
const proto = await protoFor(data)
|
|
8
|
-
peernet._protoHandler({id, proto}, peernet.connections[from] || peer, from)
|
|
8
|
+
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export default dataHandler
|
package/src/handlers/message.js
CHANGED
|
@@ -24,7 +24,7 @@ export default class MessageHandler {
|
|
|
24
24
|
* @param {String|PeernetMessage} data - data encoded message string
|
|
25
25
|
* or the messageNode itself
|
|
26
26
|
*/
|
|
27
|
-
async prepareMessage(message) {
|
|
27
|
+
async prepareMessage(message) {
|
|
28
28
|
if (message.keys.includes('signature')) {
|
|
29
29
|
message = await this.hashAndSignMessage(message)
|
|
30
30
|
}
|
package/src/identity.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MultiWallet from '@leofcoin/multi-wallet'
|
|
2
2
|
import base58 from '@vandeurenglenn/base58'
|
|
3
|
-
import {encrypt, decrypt} from '@leofcoin/identity-utils'
|
|
3
|
+
import { encrypt, decrypt } from '@leofcoin/identity-utils'
|
|
4
4
|
import QrScanner from 'qr-scanner'
|
|
5
5
|
import qrcode from 'qrcode'
|
|
6
6
|
|
|
@@ -26,31 +26,30 @@ export default class Identity {
|
|
|
26
26
|
|
|
27
27
|
async load(password?: string): Promise<void> {
|
|
28
28
|
if (password && password.includes('.txt')) {
|
|
29
|
-
|
|
30
29
|
const { readFile } = await import('fs/promises')
|
|
31
30
|
try {
|
|
32
31
|
password = (await readFile(password)).toString()
|
|
33
32
|
} catch (error) {
|
|
34
33
|
console.error(error)
|
|
35
34
|
}
|
|
36
|
-
}
|
|
35
|
+
}
|
|
37
36
|
if (!password) {
|
|
38
37
|
// @ts-ignore
|
|
39
38
|
const importee: { default: () => Promise<string> } = await import('./prompts/password.js')
|
|
40
39
|
password = await importee.default()
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
|
|
43
42
|
const accountExists = await globalThis.accountStore.has('public')
|
|
44
43
|
if (accountExists) {
|
|
45
44
|
const pub = await globalThis.accountStore.get('public')
|
|
46
|
-
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId
|
|
45
|
+
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId
|
|
47
46
|
const selected = await globalThis.walletStore.get('selected-account')
|
|
48
47
|
this.selectedAccount = new TextDecoder().decode(selected)
|
|
49
48
|
} else {
|
|
50
49
|
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
|
|
51
|
-
const {identity, accounts} = await importee.default(password, this.network)
|
|
52
|
-
await globalThis.accountStore.put('public', JSON.stringify({walletId: identity.walletId}))
|
|
53
|
-
|
|
50
|
+
const { identity, accounts } = await importee.default(password, this.network)
|
|
51
|
+
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }))
|
|
52
|
+
|
|
54
53
|
await globalThis.walletStore.put('version', String(1))
|
|
55
54
|
await globalThis.walletStore.put('accounts', JSON.stringify(accounts))
|
|
56
55
|
await globalThis.walletStore.put('selected-account', accounts[0][1])
|
|
@@ -92,11 +91,13 @@ export default class Identity {
|
|
|
92
91
|
|
|
93
92
|
async exportQR(password: string) {
|
|
94
93
|
const exported = await this.export(password)
|
|
95
|
-
return globalThis.navigator
|
|
94
|
+
return globalThis.navigator
|
|
95
|
+
? await qrcode.toDataURL(exported)
|
|
96
|
+
: await qrcode.toString(exported, { type: 'terminal' })
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
async importQR(image: File | Blob
|
|
99
|
+
async importQR(image: File | Blob, password: string) {
|
|
99
100
|
const multiWIF = await QrScanner.default.scanImage(image)
|
|
100
101
|
return this.import(password, multiWIF)
|
|
101
102
|
}
|
|
102
|
-
}
|
|
103
|
+
}
|
package/src/messages/chat.js
CHANGED
|
@@ -2,13 +2,12 @@ import proto from './../proto/chat-message.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class ChatMessage extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'ChatMessage'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(buffer) {
|
|
11
10
|
const name = 'chat-message'
|
|
12
|
-
super(buffer, proto, {name})
|
|
11
|
+
super(buffer, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
|
@@ -2,13 +2,12 @@ import proto from './../proto/data-response.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class DataMessageResponse extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetDataMessageResponse'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(data) {
|
|
11
10
|
const name = 'peernet-data-response'
|
|
12
|
-
super(data, proto, {name})
|
|
11
|
+
super(data, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/messages/data.js
CHANGED
|
@@ -5,7 +5,6 @@ import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
|
5
5
|
* @extends {CodecFormat}
|
|
6
6
|
*/
|
|
7
7
|
export default class DataMessage extends FormatInterface {
|
|
8
|
-
|
|
9
8
|
get messageName() {
|
|
10
9
|
return 'PeernetDataMessage'
|
|
11
10
|
}
|
|
@@ -13,6 +12,6 @@ export default class DataMessage extends FormatInterface {
|
|
|
13
12
|
* @param {Buffer|String|Object|DataMessage} data - The data needed to create the DataMessage
|
|
14
13
|
*/
|
|
15
14
|
constructor(data) {
|
|
16
|
-
super(data, proto, {name: 'peernet-data'})
|
|
15
|
+
super(data, proto, { name: 'peernet-data' })
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -2,13 +2,12 @@ import proto from './../proto/dht-response.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class DHTMessageResponse extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetDHTMessageResponse'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(data) {
|
|
11
10
|
const name = 'peernet-dht-response'
|
|
12
|
-
super(data, proto, {name})
|
|
11
|
+
super(data, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/messages/dht.js
CHANGED
|
@@ -10,13 +10,12 @@ import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
|
10
10
|
`
|
|
11
11
|
*/
|
|
12
12
|
export default class DHTMessage extends FormatInterface {
|
|
13
|
-
|
|
14
13
|
get messageName() {
|
|
15
14
|
return 'PeernetDHTMessage'
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
constructor(data) {
|
|
19
18
|
const name = 'peernet-dht'
|
|
20
|
-
super(data, proto, {name})
|
|
19
|
+
super(data, proto, { name })
|
|
21
20
|
}
|
|
22
21
|
}
|
|
@@ -5,7 +5,6 @@ import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
|
5
5
|
* @extends {CodecFormat}
|
|
6
6
|
*/
|
|
7
7
|
export default class PeernetFileLink extends FormatInterface {
|
|
8
|
-
|
|
9
8
|
get messageName() {
|
|
10
9
|
return 'PeernetFileLink'
|
|
11
10
|
}
|
|
@@ -13,6 +12,6 @@ export default class PeernetFileLink extends FormatInterface {
|
|
|
13
12
|
* @param {Buffer|String|Object|DataMessage} data - The data needed to create the DataMessage
|
|
14
13
|
*/
|
|
15
14
|
constructor(data) {
|
|
16
|
-
super(data, proto, {name: 'peernet-file-link'})
|
|
15
|
+
super(data, proto, { name: 'peernet-file-link' })
|
|
17
16
|
}
|
|
18
17
|
}
|
package/src/messages/file.js
CHANGED
|
@@ -5,7 +5,6 @@ import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
|
5
5
|
* @extends {CodecFormat}
|
|
6
6
|
*/
|
|
7
7
|
export default class PeernetFile extends FormatInterface {
|
|
8
|
-
|
|
9
8
|
get messageName() {
|
|
10
9
|
return 'PeernetFile'
|
|
11
10
|
}
|
|
@@ -13,6 +12,6 @@ export default class PeernetFile extends FormatInterface {
|
|
|
13
12
|
* @param {Buffer|String|Object|DataMessage} data - The data needed to create the DataMessage
|
|
14
13
|
*/
|
|
15
14
|
constructor(data) {
|
|
16
|
-
super(data, proto, {name: 'peernet-file'})
|
|
15
|
+
super(data, proto, { name: 'peernet-file' })
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -2,13 +2,12 @@ import proto from './../proto/peer-response.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class PeerMessageResponse extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetPeerMessageResponse'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(data) {
|
|
11
10
|
const name = 'peernet-peer-response'
|
|
12
|
-
super(data, proto, {name})
|
|
11
|
+
super(data, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/messages/peer.js
CHANGED
package/src/messages/peernet.js
CHANGED
|
@@ -2,13 +2,12 @@ import proto from './../proto/peernet.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class PeernetMessage extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetMessage'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(buffer) {
|
|
11
10
|
const name = 'peernet-message'
|
|
12
|
-
super(buffer, proto, {name})
|
|
11
|
+
super(buffer, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/messages/ps.js
CHANGED
package/src/messages/request.js
CHANGED
|
@@ -2,13 +2,12 @@ import proto from './../proto/request.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class RequestMessage extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetRequestMessage'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(data) {
|
|
11
10
|
const name = 'peernet-request'
|
|
12
|
-
super(data, proto, {name})
|
|
11
|
+
super(data, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/messages/response.js
CHANGED
|
@@ -2,13 +2,12 @@ import proto from './../proto/response.proto.js'
|
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
3
|
|
|
4
4
|
export default class ResponseMessage extends FormatInterface {
|
|
5
|
-
|
|
6
5
|
get messageName() {
|
|
7
6
|
return 'PeernetResponseMessage'
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
constructor(data) {
|
|
11
10
|
const name = 'peernet-response'
|
|
12
|
-
super(data, proto, {name})
|
|
11
|
+
super(data, proto, { name })
|
|
13
12
|
}
|
|
14
13
|
}
|