@libp2p/kad-dht 1.0.3 → 1.0.6

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.
Files changed (41) hide show
  1. package/dist/src/message/dht.d.ts +46 -287
  2. package/dist/src/message/dht.d.ts.map +1 -0
  3. package/dist/src/message/dht.js +75 -913
  4. package/dist/src/message/dht.js.map +1 -0
  5. package/dist/src/message/index.d.ts +5 -5
  6. package/dist/src/message/index.d.ts.map +1 -1
  7. package/dist/src/message/index.js +7 -7
  8. package/dist/src/message/index.js.map +1 -1
  9. package/dist/src/network.d.ts.map +1 -1
  10. package/dist/src/network.js +3 -3
  11. package/dist/src/network.js.map +1 -1
  12. package/dist/src/peer-routing/index.d.ts.map +1 -1
  13. package/dist/src/peer-routing/index.js +3 -0
  14. package/dist/src/peer-routing/index.js.map +1 -1
  15. package/dist/src/query/events.d.ts +4 -3
  16. package/dist/src/query/events.d.ts.map +1 -1
  17. package/dist/src/query/events.js +3 -13
  18. package/dist/src/query/events.js.map +1 -1
  19. package/dist/src/query/manager.d.ts.map +1 -1
  20. package/dist/src/query/manager.js +11 -4
  21. package/dist/src/query/manager.js.map +1 -1
  22. package/dist/src/rpc/handlers/get-value.js +1 -1
  23. package/dist/src/rpc/handlers/get-value.js.map +1 -1
  24. package/dist/src/rpc/index.d.ts.map +1 -1
  25. package/dist/src/rpc/index.js +2 -2
  26. package/dist/src/rpc/index.js.map +1 -1
  27. package/dist/src/utils.d.ts.map +1 -1
  28. package/dist/src/utils.js +6 -2
  29. package/dist/src/utils.js.map +1 -1
  30. package/package.json +19 -22
  31. package/src/message/dht.ts +112 -0
  32. package/src/message/index.ts +11 -13
  33. package/src/network.ts +3 -3
  34. package/src/peer-routing/index.ts +4 -0
  35. package/src/query/events.ts +7 -17
  36. package/src/query/manager.ts +11 -5
  37. package/src/rpc/handlers/get-value.ts +1 -1
  38. package/src/rpc/index.ts +3 -3
  39. package/src/utils.ts +8 -2
  40. package/src/message/dht.d.ts +0 -297
  41. package/src/message/dht.js +0 -921
@@ -0,0 +1,112 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+
4
+ import { encodeMessage, decodeMessage, message, bytes, string, enumeration, int32 } from 'protons-runtime'
5
+
6
+ export interface Record {
7
+ key?: Uint8Array
8
+ value?: Uint8Array
9
+ author?: Uint8Array
10
+ signature?: Uint8Array
11
+ timeReceived?: string
12
+ }
13
+
14
+ export namespace Record {
15
+ export const codec = () => {
16
+ return message<Record>({
17
+ 1: { name: 'key', codec: bytes, optional: true },
18
+ 2: { name: 'value', codec: bytes, optional: true },
19
+ 3: { name: 'author', codec: bytes, optional: true },
20
+ 4: { name: 'signature', codec: bytes, optional: true },
21
+ 5: { name: 'timeReceived', codec: string, optional: true }
22
+ })
23
+ }
24
+
25
+ export const encode = (obj: Record): Uint8Array => {
26
+ return encodeMessage(obj, Record.codec())
27
+ }
28
+
29
+ export const decode = (buf: Uint8Array): Record => {
30
+ return decodeMessage(buf, Record.codec())
31
+ }
32
+ }
33
+
34
+ export interface Message {
35
+ type?: Message.MessageType
36
+ clusterLevelRaw?: number
37
+ key?: Uint8Array
38
+ record?: Uint8Array
39
+ closerPeers: Message.Peer[]
40
+ providerPeers: Message.Peer[]
41
+ }
42
+
43
+ export namespace Message {
44
+ export enum MessageType {
45
+ PUT_VALUE = 'PUT_VALUE',
46
+ GET_VALUE = 'GET_VALUE',
47
+ ADD_PROVIDER = 'ADD_PROVIDER',
48
+ GET_PROVIDERS = 'GET_PROVIDERS',
49
+ FIND_NODE = 'FIND_NODE',
50
+ PING = 'PING'
51
+ }
52
+
53
+ export namespace MessageType {
54
+ export const codec = () => {
55
+ return enumeration<typeof MessageType>(MessageType)
56
+ }
57
+ }
58
+ export enum ConnectionType {
59
+ NOT_CONNECTED = 'NOT_CONNECTED',
60
+ CONNECTED = 'CONNECTED',
61
+ CAN_CONNECT = 'CAN_CONNECT',
62
+ CANNOT_CONNECT = 'CANNOT_CONNECT'
63
+ }
64
+
65
+ export namespace ConnectionType {
66
+ export const codec = () => {
67
+ return enumeration<typeof ConnectionType>(ConnectionType)
68
+ }
69
+ }
70
+ export interface Peer {
71
+ id?: Uint8Array
72
+ addrs: Uint8Array[]
73
+ connection?: Message.ConnectionType
74
+ }
75
+
76
+ export namespace Peer {
77
+ export const codec = () => {
78
+ return message<Peer>({
79
+ 1: { name: 'id', codec: bytes, optional: true },
80
+ 2: { name: 'addrs', codec: bytes, repeats: true },
81
+ 3: { name: 'connection', codec: Message.ConnectionType.codec(), optional: true }
82
+ })
83
+ }
84
+
85
+ export const encode = (obj: Peer): Uint8Array => {
86
+ return encodeMessage(obj, Peer.codec())
87
+ }
88
+
89
+ export const decode = (buf: Uint8Array): Peer => {
90
+ return decodeMessage(buf, Peer.codec())
91
+ }
92
+ }
93
+
94
+ export const codec = () => {
95
+ return message<Message>({
96
+ 1: { name: 'type', codec: Message.MessageType.codec(), optional: true },
97
+ 10: { name: 'clusterLevelRaw', codec: int32, optional: true },
98
+ 2: { name: 'key', codec: bytes, optional: true },
99
+ 3: { name: 'record', codec: bytes, optional: true },
100
+ 8: { name: 'closerPeers', codec: Message.Peer.codec(), repeats: true },
101
+ 9: { name: 'providerPeers', codec: Message.Peer.codec(), repeats: true }
102
+ })
103
+ }
104
+
105
+ export const encode = (obj: Message): Uint8Array => {
106
+ return encodeMessage(obj, Message.codec())
107
+ }
108
+
109
+ export const decode = (buf: Uint8Array): Message => {
110
+ return decodeMessage(buf, Message.codec())
111
+ }
112
+ }
@@ -1,33 +1,31 @@
1
1
  import { peerIdFromBytes } from '@libp2p/peer-id'
2
2
  import { Multiaddr } from '@multiformats/multiaddr'
3
3
  import { Libp2pRecord } from '@libp2p/record'
4
- import Proto from './dht.js'
4
+ import { Message as PBMessage } from './dht.js'
5
5
  import type { PeerInfo } from '@libp2p/interfaces/peer-info'
6
6
 
7
- export const MESSAGE_TYPE = Proto.Message.MessageType
8
- export const CONNECTION_TYPE = Proto.Message.ConnectionType
7
+ export const MESSAGE_TYPE = PBMessage.MessageType
8
+ export const CONNECTION_TYPE = PBMessage.ConnectionType
9
9
  export const MESSAGE_TYPE_LOOKUP = Object.keys(MESSAGE_TYPE)
10
10
 
11
- type ConnectionType = 0|1|2|3|4
12
-
13
11
  interface PBPeer {
14
12
  id: Uint8Array
15
13
  addrs: Uint8Array[]
16
- connection: ConnectionType
14
+ connection: PBMessage.ConnectionType
17
15
  }
18
16
 
19
17
  /**
20
18
  * Represents a single DHT control message.
21
19
  */
22
20
  export class Message {
23
- public type: Proto.Message.MessageType
21
+ public type: PBMessage.MessageType
24
22
  public key: Uint8Array
25
23
  private clusterLevelRaw: number
26
24
  public closerPeers: PeerInfo[]
27
25
  public providerPeers: PeerInfo[]
28
26
  public record?: Libp2pRecord
29
27
 
30
- constructor (type: Proto.Message.MessageType, key: Uint8Array, level: number) {
28
+ constructor (type: PBMessage.MessageType, key: Uint8Array, level: number) {
31
29
  if (!(key instanceof Uint8Array)) {
32
30
  throw new Error('Key must be a Uint8Array')
33
31
  }
@@ -60,23 +58,23 @@ export class Message {
60
58
  * Encode into protobuf
61
59
  */
62
60
  serialize () {
63
- return Proto.Message.encode({
61
+ return PBMessage.encode({
64
62
  key: this.key,
65
63
  type: this.type,
66
64
  clusterLevelRaw: this.clusterLevelRaw,
67
65
  closerPeers: this.closerPeers.map(toPbPeer),
68
66
  providerPeers: this.providerPeers.map(toPbPeer),
69
67
  record: this.record == null ? undefined : this.record.serialize()
70
- }).finish()
68
+ })
71
69
  }
72
70
 
73
71
  /**
74
72
  * Decode from protobuf
75
73
  */
76
74
  static deserialize (raw: Uint8Array) {
77
- const dec = Proto.Message.decode(raw)
75
+ const dec = PBMessage.decode(raw)
78
76
 
79
- const msg = new Message(dec.type ?? 0, dec.key ?? Uint8Array.from([]), dec.clusterLevelRaw ?? 0)
77
+ const msg = new Message(dec.type ?? PBMessage.MessageType.PUT_VALUE, dec.key ?? Uint8Array.from([]), dec.clusterLevelRaw ?? 0)
80
78
  msg.closerPeers = dec.closerPeers.map(fromPbPeer)
81
79
  msg.providerPeers = dec.providerPeers.map(fromPbPeer)
82
80
 
@@ -98,7 +96,7 @@ function toPbPeer (peer: PeerInfo) {
98
96
  return output
99
97
  }
100
98
 
101
- function fromPbPeer (peer: Proto.Message.IPeer) {
99
+ function fromPbPeer (peer: PBMessage.Peer) {
102
100
  if (peer.id == null) {
103
101
  throw new Error('Invalid peer in message')
104
102
  }
package/src/network.ts CHANGED
@@ -3,7 +3,7 @@ import { pipe } from 'it-pipe'
3
3
  import * as lp from 'it-length-prefixed'
4
4
  import drain from 'it-drain'
5
5
  import first from 'it-first'
6
- import { Message, MESSAGE_TYPE_LOOKUP } from './message/index.js'
6
+ import { Message } from './message/index.js'
7
7
  import { EventEmitter, CustomEvent } from '@libp2p/interfaces'
8
8
  import {
9
9
  dialingPeerEvent,
@@ -86,7 +86,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
86
86
  return
87
87
  }
88
88
 
89
- this.log('sending %s to %p', MESSAGE_TYPE_LOOKUP[msg.type], to)
89
+ this.log('sending %s to %p', msg.type, to)
90
90
 
91
91
  try {
92
92
  yield dialingPeerEvent({ peer: to })
@@ -117,7 +117,7 @@ export class Network extends EventEmitter<NetworkEvents> implements Startable, I
117
117
  return
118
118
  }
119
119
 
120
- this.log('sending %s to %p', MESSAGE_TYPE_LOOKUP[msg.type], to)
120
+ this.log('sending %s to %p', msg.type, to)
121
121
 
122
122
  yield dialingPeerEvent({ peer: to })
123
123
 
@@ -286,6 +286,10 @@ export class PeerRouting implements Initializable {
286
286
  * Throws an error if the record is invalid.
287
287
  */
288
288
  async _verifyRecordOnline (record: DHTRecord) {
289
+ if (record.timeReceived == null) {
290
+ throw errcode(new Error('invalid record received'), 'ERR_INVALID_RECORD')
291
+ }
292
+
289
293
  await verifyRecord(this.validators, new Libp2pRecord(record.key, record.value, record.timeReceived))
290
294
  }
291
295
 
@@ -1,21 +1,13 @@
1
1
  import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
2
- import type { SendingQueryEvent, PeerResponseEvent, MessageType, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht'
2
+ import type { Message } from '../message/dht.js'
3
+ import type { SendingQueryEvent, PeerResponseEvent, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht'
3
4
  import type { PeerInfo } from '@libp2p/interfaces/peer-info'
4
5
  import type { PeerId } from '@libp2p/interfaces/peer-id'
5
6
  import type { Libp2pRecord } from '@libp2p/record'
6
7
 
7
- const MESSAGE_NAMES = [
8
- 'PUT_VALUE',
9
- 'GET_VALUE',
10
- 'ADD_PROVIDER',
11
- 'GET_PROVIDERS',
12
- 'FIND_NODE',
13
- 'PING'
14
- ]
15
-
16
8
  export interface QueryEventFields {
17
9
  to: PeerId
18
- type: MessageType
10
+ type: Message.MessageType
19
11
  }
20
12
 
21
13
  export function sendingQueryEvent (fields: QueryEventFields): SendingQueryEvent {
@@ -23,15 +15,14 @@ export function sendingQueryEvent (fields: QueryEventFields): SendingQueryEvent
23
15
  ...fields,
24
16
  name: 'SENDING_QUERY',
25
17
  type: 0,
26
- // @ts-expect-error cannot look up values like this
27
- messageName: MESSAGE_TYPE_LOOKUP[fields.type],
28
- messageType: fields.type
18
+ messageName: fields.type,
19
+ messageType: MESSAGE_TYPE_LOOKUP.indexOf(fields.type.toString())
29
20
  }
30
21
  }
31
22
 
32
23
  export interface PeerResponseEventField {
33
24
  from: PeerId
34
- messageType: MessageType
25
+ messageType: Message.MessageType
35
26
  closer?: PeerInfo[]
36
27
  providers?: PeerInfo[]
37
28
  record?: Libp2pRecord
@@ -42,8 +33,7 @@ export function peerResponseEvent (fields: PeerResponseEventField): PeerResponse
42
33
  ...fields,
43
34
  name: 'PEER_RESPONSE',
44
35
  type: 1,
45
- // @ts-expect-error cannot look up values like this
46
- messageName: MESSAGE_NAMES[fields.messageType],
36
+ messageName: fields.messageType,
47
37
  closer: (fields.closer != null) ? fields.closer : [],
48
38
  providers: (fields.providers != null) ? fields.providers : []
49
39
  }
@@ -6,10 +6,8 @@ import {
6
6
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7
7
  import { queryPath } from './query-path.js'
8
8
  import merge from 'it-merge'
9
- import {
10
- // @ts-expect-error only defined in node 15+
11
- setMaxListeners
12
- } from 'events'
9
+ // @ts-expect-error setMaxListeners is missing from the types
10
+ import { setMaxListeners } from 'events'
13
11
  import { EventEmitter, CustomEvent } from '@libp2p/interfaces'
14
12
  import { logger } from '@libp2p/logger'
15
13
  import type { PeerId } from '@libp2p/interfaces/peer-id'
@@ -91,6 +89,14 @@ export class QueryManager implements Startable, Initializable {
91
89
  // don't let queries run forever
92
90
  timeoutController = new TimeoutController(DEFAULT_QUERY_TIMEOUT)
93
91
  options.signal = timeoutController.signal
92
+
93
+ // this signal will get listened to for network requests, etc
94
+ // so make sure we don't make a lot of noise in the logs
95
+ try {
96
+ if (setMaxListeners != null) {
97
+ setMaxListeners(Infinity, timeoutController.signal)
98
+ }
99
+ } catch {} // fails on node < 15.4
94
100
  }
95
101
 
96
102
  // allow us to stop queries on shut down
@@ -108,7 +114,7 @@ export class QueryManager implements Startable, Initializable {
108
114
  // so make sure we don't make a lot of noise in the logs
109
115
  try {
110
116
  if (setMaxListeners != null) {
111
- setMaxListeners(0, signal)
117
+ setMaxListeners(Infinity, signal)
112
118
  }
113
119
  } catch {} // fails on node < 15.4
114
120
 
@@ -63,7 +63,7 @@ export class GetValueHandler implements DHTMessageHandler, Initializable {
63
63
 
64
64
  if (pubKey != null) {
65
65
  log('returning found public key')
66
- response.record = new Libp2pRecord(key, pubKey)
66
+ response.record = new Libp2pRecord(key, pubKey, new Date())
67
67
  return response
68
68
  }
69
69
  }
package/src/rpc/index.ts CHANGED
@@ -3,7 +3,7 @@ import * as lp from 'it-length-prefixed'
3
3
  import { Logger, logger } from '@libp2p/logger'
4
4
  import type { RoutingTable } from '../routing-table'
5
5
  import type { PeerId } from '@libp2p/interfaces/peer-id'
6
- import { Message, MESSAGE_TYPE, MESSAGE_TYPE_LOOKUP } from '../message/index.js'
6
+ import { Message, MESSAGE_TYPE } from '../message/index.js'
7
7
  import { AddProviderHandler } from './handlers/add-provider.js'
8
8
  import { FindNodeHandler } from './handlers/find-node.js'
9
9
  import { GetProvidersHandler } from './handlers/get-providers.js'
@@ -29,7 +29,7 @@ export interface RPCInit {
29
29
  }
30
30
 
31
31
  export class RPC implements Initializable {
32
- private readonly handlers: Record<number, DHTMessageHandler & Initializable>
32
+ private readonly handlers: Record<string, DHTMessageHandler & Initializable>
33
33
  private readonly routingTable: RoutingTable
34
34
  private readonly log: Logger
35
35
 
@@ -99,7 +99,7 @@ export class RPC implements Initializable {
99
99
  for await (const msg of source) {
100
100
  // handle the message
101
101
  const desMessage = Message.deserialize(msg.slice())
102
- self.log('incoming %s from %p', MESSAGE_TYPE_LOOKUP[desMessage.type], peerId)
102
+ self.log('incoming %s from %p', desMessage.type, peerId)
103
103
  const res = await self.handleMessage(peerId, desMessage)
104
104
 
105
105
  // Not all handlers will return a response
package/src/utils.ts CHANGED
@@ -23,7 +23,10 @@ export function removePrivateAddresses (peer: PeerInfo): PeerInfo {
23
23
  return false
24
24
  }
25
25
 
26
- // @ts-expect-error types are wrong https://github.com/frenchbread/private-ip/issues/18
26
+ if (addr == null) {
27
+ return false
28
+ }
29
+
27
30
  return !isPrivateIp(addr)
28
31
  })
29
32
  }
@@ -39,7 +42,10 @@ export function removePublicAddresses (peer: PeerInfo): PeerInfo {
39
42
  return false
40
43
  }
41
44
 
42
- // @ts-expect-error types are wrong https://github.com/frenchbread/private-ip/issues/18
45
+ if (addr == null) {
46
+ return false
47
+ }
48
+
43
49
  return isPrivateIp(addr)
44
50
  })
45
51
  }
@@ -1,297 +0,0 @@
1
- import * as $protobuf from "protobufjs";
2
- /** Properties of a Record. */
3
- export interface IRecord {
4
-
5
- /** Record key */
6
- key?: (Uint8Array|null);
7
-
8
- /** Record value */
9
- value?: (Uint8Array|null);
10
-
11
- /** Record author */
12
- author?: (Uint8Array|null);
13
-
14
- /** Record signature */
15
- signature?: (Uint8Array|null);
16
-
17
- /** Record timeReceived */
18
- timeReceived?: (string|null);
19
- }
20
-
21
- /** Represents a Record. */
22
- export class Record implements IRecord {
23
-
24
- /**
25
- * Constructs a new Record.
26
- * @param [p] Properties to set
27
- */
28
- constructor(p?: IRecord);
29
-
30
- /** Record key. */
31
- public key?: (Uint8Array|null);
32
-
33
- /** Record value. */
34
- public value?: (Uint8Array|null);
35
-
36
- /** Record author. */
37
- public author?: (Uint8Array|null);
38
-
39
- /** Record signature. */
40
- public signature?: (Uint8Array|null);
41
-
42
- /** Record timeReceived. */
43
- public timeReceived?: (string|null);
44
-
45
- /** Record _key. */
46
- public _key?: "key";
47
-
48
- /** Record _value. */
49
- public _value?: "value";
50
-
51
- /** Record _author. */
52
- public _author?: "author";
53
-
54
- /** Record _signature. */
55
- public _signature?: "signature";
56
-
57
- /** Record _timeReceived. */
58
- public _timeReceived?: "timeReceived";
59
-
60
- /**
61
- * Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
62
- * @param m Record message or plain object to encode
63
- * @param [w] Writer to encode to
64
- * @returns Writer
65
- */
66
- public static encode(m: IRecord, w?: $protobuf.Writer): $protobuf.Writer;
67
-
68
- /**
69
- * Decodes a Record message from the specified reader or buffer.
70
- * @param r Reader or buffer to decode from
71
- * @param [l] Message length if known beforehand
72
- * @returns Record
73
- * @throws {Error} If the payload is not a reader or valid buffer
74
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
75
- */
76
- public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Record;
77
-
78
- /**
79
- * Creates a Record message from a plain object. Also converts values to their respective internal types.
80
- * @param d Plain object
81
- * @returns Record
82
- */
83
- public static fromObject(d: { [k: string]: any }): Record;
84
-
85
- /**
86
- * Creates a plain object from a Record message. Also converts values to other types if specified.
87
- * @param m Record
88
- * @param [o] Conversion options
89
- * @returns Plain object
90
- */
91
- public static toObject(m: Record, o?: $protobuf.IConversionOptions): { [k: string]: any };
92
-
93
- /**
94
- * Converts this Record to JSON.
95
- * @returns JSON object
96
- */
97
- public toJSON(): { [k: string]: any };
98
- }
99
-
100
- /** Properties of a Message. */
101
- export interface IMessage {
102
-
103
- /** Message type */
104
- type?: (Message.MessageType|null);
105
-
106
- /** Message clusterLevelRaw */
107
- clusterLevelRaw?: (number|null);
108
-
109
- /** Message key */
110
- key?: (Uint8Array|null);
111
-
112
- /** Message record */
113
- record?: (Uint8Array|null);
114
-
115
- /** Message closerPeers */
116
- closerPeers?: (Message.IPeer[]|null);
117
-
118
- /** Message providerPeers */
119
- providerPeers?: (Message.IPeer[]|null);
120
- }
121
-
122
- /** Represents a Message. */
123
- export class Message implements IMessage {
124
-
125
- /**
126
- * Constructs a new Message.
127
- * @param [p] Properties to set
128
- */
129
- constructor(p?: IMessage);
130
-
131
- /** Message type. */
132
- public type?: (Message.MessageType|null);
133
-
134
- /** Message clusterLevelRaw. */
135
- public clusterLevelRaw?: (number|null);
136
-
137
- /** Message key. */
138
- public key?: (Uint8Array|null);
139
-
140
- /** Message record. */
141
- public record?: (Uint8Array|null);
142
-
143
- /** Message closerPeers. */
144
- public closerPeers: Message.IPeer[];
145
-
146
- /** Message providerPeers. */
147
- public providerPeers: Message.IPeer[];
148
-
149
- /** Message _type. */
150
- public _type?: "type";
151
-
152
- /** Message _clusterLevelRaw. */
153
- public _clusterLevelRaw?: "clusterLevelRaw";
154
-
155
- /** Message _key. */
156
- public _key?: "key";
157
-
158
- /** Message _record. */
159
- public _record?: "record";
160
-
161
- /**
162
- * Encodes the specified Message message. Does not implicitly {@link Message.verify|verify} messages.
163
- * @param m Message message or plain object to encode
164
- * @param [w] Writer to encode to
165
- * @returns Writer
166
- */
167
- public static encode(m: IMessage, w?: $protobuf.Writer): $protobuf.Writer;
168
-
169
- /**
170
- * Decodes a Message message from the specified reader or buffer.
171
- * @param r Reader or buffer to decode from
172
- * @param [l] Message length if known beforehand
173
- * @returns Message
174
- * @throws {Error} If the payload is not a reader or valid buffer
175
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
176
- */
177
- public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Message;
178
-
179
- /**
180
- * Creates a Message message from a plain object. Also converts values to their respective internal types.
181
- * @param d Plain object
182
- * @returns Message
183
- */
184
- public static fromObject(d: { [k: string]: any }): Message;
185
-
186
- /**
187
- * Creates a plain object from a Message message. Also converts values to other types if specified.
188
- * @param m Message
189
- * @param [o] Conversion options
190
- * @returns Plain object
191
- */
192
- public static toObject(m: Message, o?: $protobuf.IConversionOptions): { [k: string]: any };
193
-
194
- /**
195
- * Converts this Message to JSON.
196
- * @returns JSON object
197
- */
198
- public toJSON(): { [k: string]: any };
199
- }
200
-
201
- export namespace Message {
202
-
203
- /** MessageType enum. */
204
- enum MessageType {
205
- PUT_VALUE = 0,
206
- GET_VALUE = 1,
207
- ADD_PROVIDER = 2,
208
- GET_PROVIDERS = 3,
209
- FIND_NODE = 4,
210
- PING = 5
211
- }
212
-
213
- /** ConnectionType enum. */
214
- enum ConnectionType {
215
- NOT_CONNECTED = 0,
216
- CONNECTED = 1,
217
- CAN_CONNECT = 2,
218
- CANNOT_CONNECT = 3
219
- }
220
-
221
- /** Properties of a Peer. */
222
- interface IPeer {
223
-
224
- /** Peer id */
225
- id?: (Uint8Array|null);
226
-
227
- /** Peer addrs */
228
- addrs?: (Uint8Array[]|null);
229
-
230
- /** Peer connection */
231
- connection?: (Message.ConnectionType|null);
232
- }
233
-
234
- /** Represents a Peer. */
235
- class Peer implements IPeer {
236
-
237
- /**
238
- * Constructs a new Peer.
239
- * @param [p] Properties to set
240
- */
241
- constructor(p?: Message.IPeer);
242
-
243
- /** Peer id. */
244
- public id?: (Uint8Array|null);
245
-
246
- /** Peer addrs. */
247
- public addrs: Uint8Array[];
248
-
249
- /** Peer connection. */
250
- public connection?: (Message.ConnectionType|null);
251
-
252
- /** Peer _id. */
253
- public _id?: "id";
254
-
255
- /** Peer _connection. */
256
- public _connection?: "connection";
257
-
258
- /**
259
- * Encodes the specified Peer message. Does not implicitly {@link Message.Peer.verify|verify} messages.
260
- * @param m Peer message or plain object to encode
261
- * @param [w] Writer to encode to
262
- * @returns Writer
263
- */
264
- public static encode(m: Message.IPeer, w?: $protobuf.Writer): $protobuf.Writer;
265
-
266
- /**
267
- * Decodes a Peer message from the specified reader or buffer.
268
- * @param r Reader or buffer to decode from
269
- * @param [l] Message length if known beforehand
270
- * @returns Peer
271
- * @throws {Error} If the payload is not a reader or valid buffer
272
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
273
- */
274
- public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Message.Peer;
275
-
276
- /**
277
- * Creates a Peer message from a plain object. Also converts values to their respective internal types.
278
- * @param d Plain object
279
- * @returns Peer
280
- */
281
- public static fromObject(d: { [k: string]: any }): Message.Peer;
282
-
283
- /**
284
- * Creates a plain object from a Peer message. Also converts values to other types if specified.
285
- * @param m Peer
286
- * @param [o] Conversion options
287
- * @returns Plain object
288
- */
289
- public static toObject(m: Message.Peer, o?: $protobuf.IConversionOptions): { [k: string]: any };
290
-
291
- /**
292
- * Converts this Peer to JSON.
293
- * @returns JSON object
294
- */
295
- public toJSON(): { [k: string]: any };
296
- }
297
- }