From e3b76303227b3c7fafa3e934a1b56cab75d508b6 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 10 Aug 2022 14:50:17 +0100 Subject: [PATCH] fix: update all deps --- lerna.json | 4 +- packages/libp2p-daemon-client/package.json | 4 +- .../libp2p-daemon-client/test/dht.spec.ts | 2 +- packages/libp2p-daemon-protocol/package.json | 6 +- packages/libp2p-daemon-protocol/src/index.ts | 1458 +++++++++++++++-- packages/libp2p-daemon-server/package.json | 2 +- packages/libp2p-daemon-server/src/index.ts | 5 + packages/libp2p-daemon-server/src/pubsub.ts | 23 +- 8 files changed, 1353 insertions(+), 151 deletions(-) diff --git a/lerna.json b/lerna.json index aa6d0004..d7a23368 100644 --- a/lerna.json +++ b/lerna.json @@ -1,8 +1,6 @@ { "lerna": "4.0.0", - "packages": [ - "packages/*" - ], + "useWorkspaces": true, "version": "independent", "command": { "run": { diff --git a/packages/libp2p-daemon-client/package.json b/packages/libp2p-daemon-client/package.json index ab8ced1a..2bd9165b 100644 --- a/packages/libp2p-daemon-client/package.json +++ b/packages/libp2p-daemon-client/package.json @@ -150,9 +150,9 @@ "@libp2p/daemon-server": "^2.0.0", "@libp2p/interface-compliance-tests": "^3.0.1", "@libp2p/interface-dht": "^1.0.0", - "@libp2p/interface-mocks": "^3.0.2", + "@libp2p/interface-mocks": "^4.0.1", "@libp2p/interface-peer-store": "^1.0.0", - "@libp2p/interface-pubsub": "^1.0.1", + "@libp2p/interface-pubsub": "^2.0.1", "@libp2p/peer-id-factory": "^1.0.9", "aegir": "^37.2.0", "it-all": "^1.0.6", diff --git a/packages/libp2p-daemon-client/test/dht.spec.ts b/packages/libp2p-daemon-client/test/dht.spec.ts index 6d0dffcb..0fce6f29 100644 --- a/packages/libp2p-daemon-client/test/dht.spec.ts +++ b/packages/libp2p-daemon-client/test/dht.spec.ts @@ -198,7 +198,7 @@ describe('daemon dht client', function () { const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - dht.getClosestPeers.withArgs(cid.bytes).returns(async function * () { + dht.getClosestPeers.returns(async function * () { const event: PeerResponseEvent = { name: 'PEER_RESPONSE', type: EventTypes.PEER_RESPONSE, diff --git a/packages/libp2p-daemon-protocol/package.json b/packages/libp2p-daemon-protocol/package.json index 6b3d675f..52f49b04 100644 --- a/packages/libp2p-daemon-protocol/package.json +++ b/packages/libp2p-daemon-protocol/package.json @@ -159,11 +159,11 @@ "dependencies": { "@libp2p/interface-transport": "^1.0.0", "it-handshake": "^4.0.0", - "protons-runtime": "^2.0.2", - "uint8arraylist": "^2.0.0" + "protons-runtime": "^3.0.1", + "uint8arraylist": "^2.3.2" }, "devDependencies": { "aegir": "^37.2.0", - "protons": "^4.0.1" + "protons": "^5.0.0" } } diff --git a/packages/libp2p-daemon-protocol/src/index.ts b/packages/libp2p-daemon-protocol/src/index.ts index 3c0a9583..e2f06279 100644 --- a/packages/libp2p-daemon-protocol/src/index.ts +++ b/packages/libp2p-daemon-protocol/src/index.ts @@ -1,9 +1,9 @@ /* eslint-disable import/export */ /* eslint-disable @typescript-eslint/no-namespace */ -import { enumeration, encodeMessage, decodeMessage, message, bytes, int64, string, int32 } from 'protons-runtime' -import type { Codec } from 'protons-runtime' +import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' +import type { Codec } from 'protons-runtime' export interface Request { type: Request.Type @@ -46,25 +46,123 @@ export namespace Request { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: Request.Type.codec() }, - 2: { name: 'connect', codec: ConnectRequest.codec(), optional: true }, - 3: { name: 'streamOpen', codec: StreamOpenRequest.codec(), optional: true }, - 4: { name: 'streamHandler', codec: StreamHandlerRequest.codec(), optional: true }, - 5: { name: 'dht', codec: DHTRequest.codec(), optional: true }, - 6: { name: 'connManager', codec: ConnManagerRequest.codec(), optional: true }, - 7: { name: 'disconnect', codec: DisconnectRequest.codec(), optional: true }, - 8: { name: 'pubsub', codec: PSRequest.codec(), optional: true }, - 9: { name: 'peerStore', codec: PeerstoreRequest.codec(), optional: true } - }) - } - - export const encode = (obj: Request): Uint8ArrayList => { + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + Request.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.connect != null) { + writer.uint32(18) + ConnectRequest.codec().encode(obj.connect, writer) + } + + if (obj.streamOpen != null) { + writer.uint32(26) + StreamOpenRequest.codec().encode(obj.streamOpen, writer) + } + + if (obj.streamHandler != null) { + writer.uint32(34) + StreamHandlerRequest.codec().encode(obj.streamHandler, writer) + } + + if (obj.dht != null) { + writer.uint32(42) + DHTRequest.codec().encode(obj.dht, writer) + } + + if (obj.connManager != null) { + writer.uint32(50) + ConnManagerRequest.codec().encode(obj.connManager, writer) + } + + if (obj.disconnect != null) { + writer.uint32(58) + DisconnectRequest.codec().encode(obj.disconnect, writer) + } + + if (obj.pubsub != null) { + writer.uint32(66) + PSRequest.codec().encode(obj.pubsub, writer) + } + + if (obj.peerStore != null) { + writer.uint32(74) + PeerstoreRequest.codec().encode(obj.peerStore, writer) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = Request.Type.codec().decode(reader) + break + case 2: + obj.connect = ConnectRequest.codec().decode(reader, reader.uint32()) + break + case 3: + obj.streamOpen = StreamOpenRequest.codec().decode(reader, reader.uint32()) + break + case 4: + obj.streamHandler = StreamHandlerRequest.codec().decode(reader, reader.uint32()) + break + case 5: + obj.dht = DHTRequest.codec().decode(reader, reader.uint32()) + break + case 6: + obj.connManager = ConnManagerRequest.codec().decode(reader, reader.uint32()) + break + case 7: + obj.disconnect = DisconnectRequest.codec().decode(reader, reader.uint32()) + break + case 8: + obj.pubsub = PSRequest.codec().decode(reader, reader.uint32()) + break + case 9: + obj.peerStore = PeerstoreRequest.codec().decode(reader, reader.uint32()) + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + return obj + }) + } + + return _codec + } + + export const encode = (obj: Request): Uint8Array => { return encodeMessage(obj, Request.codec()) } @@ -97,24 +195,126 @@ export namespace Response { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: Response.Type.codec() }, - 2: { name: 'error', codec: ErrorResponse.codec(), optional: true }, - 3: { name: 'streamInfo', codec: StreamInfo.codec(), optional: true }, - 4: { name: 'identify', codec: IdentifyResponse.codec(), optional: true }, - 5: { name: 'dht', codec: DHTResponse.codec(), optional: true }, - 6: { name: 'peers', codec: PeerInfo.codec(), repeats: true }, - 7: { name: 'pubsub', codec: PSResponse.codec(), optional: true }, - 8: { name: 'peerStore', codec: PeerstoreResponse.codec(), optional: true } - }) - } - - export const encode = (obj: Response): Uint8ArrayList => { + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + Response.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.error != null) { + writer.uint32(18) + ErrorResponse.codec().encode(obj.error, writer) + } + + if (obj.streamInfo != null) { + writer.uint32(26) + StreamInfo.codec().encode(obj.streamInfo, writer) + } + + if (obj.identify != null) { + writer.uint32(34) + IdentifyResponse.codec().encode(obj.identify, writer) + } + + if (obj.dht != null) { + writer.uint32(42) + DHTResponse.codec().encode(obj.dht, writer) + } + + if (obj.peers != null) { + for (const value of obj.peers) { + writer.uint32(50) + PeerInfo.codec().encode(value, writer) + } + } else { + throw new Error('Protocol error: required field "peers" was not found in object') + } + + if (obj.pubsub != null) { + writer.uint32(58) + PSResponse.codec().encode(obj.pubsub, writer) + } + + if (obj.peerStore != null) { + writer.uint32(66) + PeerstoreResponse.codec().encode(obj.peerStore, writer) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = Response.Type.codec().decode(reader) + break + case 2: + obj.error = ErrorResponse.codec().decode(reader, reader.uint32()) + break + case 3: + obj.streamInfo = StreamInfo.codec().decode(reader, reader.uint32()) + break + case 4: + obj.identify = IdentifyResponse.codec().decode(reader, reader.uint32()) + break + case 5: + obj.dht = DHTResponse.codec().decode(reader, reader.uint32()) + break + case 6: + obj.peers = obj.peers ?? [] + obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32())) + break + case 7: + obj.pubsub = PSResponse.codec().decode(reader, reader.uint32()) + break + case 8: + obj.peerStore = PeerstoreResponse.codec().decode(reader, reader.uint32()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.peers = obj.peers ?? [] + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + if (obj.peers == null) { + throw new Error('Protocol error: value for required field "peers" was not found in protobuf') + } + + return obj + }) + } + + return _codec + } + + export const encode = (obj: Response): Uint8Array => { return encodeMessage(obj, Response.codec()) } @@ -129,14 +329,74 @@ export interface IdentifyResponse { } export namespace IdentifyResponse { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'id', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.id != null) { + writer.uint32(10) + writer.bytes(obj.id) + } else { + throw new Error('Protocol error: required field "id" was not found in object') + } + + if (obj.addrs != null) { + for (const value of obj.addrs) { + writer.uint32(18) + writer.bytes(value) + } + } else { + throw new Error('Protocol error: required field "addrs" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.id = reader.bytes() + break + case 2: + obj.addrs = obj.addrs ?? [] + obj.addrs.push(reader.bytes()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.addrs = obj.addrs ?? [] + + if (obj.id == null) { + throw new Error('Protocol error: value for required field "id" was not found in protobuf') + } + + if (obj.addrs == null) { + throw new Error('Protocol error: value for required field "addrs" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: IdentifyResponse): Uint8ArrayList => { + export const encode = (obj: IdentifyResponse): Uint8Array => { return encodeMessage(obj, IdentifyResponse.codec()) } @@ -152,15 +412,82 @@ export interface ConnectRequest { } export namespace ConnectRequest { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true }, - 3: { name: 'timeout', codec: int64, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.peer != null) { + writer.uint32(10) + writer.bytes(obj.peer) + } else { + throw new Error('Protocol error: required field "peer" was not found in object') + } + + if (obj.addrs != null) { + for (const value of obj.addrs) { + writer.uint32(18) + writer.bytes(value) + } + } else { + throw new Error('Protocol error: required field "addrs" was not found in object') + } + + if (obj.timeout != null) { + writer.uint32(24) + writer.int64(obj.timeout) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.peer = reader.bytes() + break + case 2: + obj.addrs = obj.addrs ?? [] + obj.addrs.push(reader.bytes()) + break + case 3: + obj.timeout = reader.int64() + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.addrs = obj.addrs ?? [] + + if (obj.peer == null) { + throw new Error('Protocol error: value for required field "peer" was not found in protobuf') + } + + if (obj.addrs == null) { + throw new Error('Protocol error: value for required field "addrs" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: ConnectRequest): Uint8ArrayList => { + export const encode = (obj: ConnectRequest): Uint8Array => { return encodeMessage(obj, ConnectRequest.codec()) } @@ -176,15 +503,82 @@ export interface StreamOpenRequest { } export namespace StreamOpenRequest { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'proto', codec: string, repeats: true }, - 3: { name: 'timeout', codec: int64, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.peer != null) { + writer.uint32(10) + writer.bytes(obj.peer) + } else { + throw new Error('Protocol error: required field "peer" was not found in object') + } + + if (obj.proto != null) { + for (const value of obj.proto) { + writer.uint32(18) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "proto" was not found in object') + } + + if (obj.timeout != null) { + writer.uint32(24) + writer.int64(obj.timeout) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.peer = reader.bytes() + break + case 2: + obj.proto = obj.proto ?? [] + obj.proto.push(reader.string()) + break + case 3: + obj.timeout = reader.int64() + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.proto = obj.proto ?? [] + + if (obj.peer == null) { + throw new Error('Protocol error: value for required field "peer" was not found in protobuf') + } + + if (obj.proto == null) { + throw new Error('Protocol error: value for required field "proto" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: StreamOpenRequest): Uint8ArrayList => { + export const encode = (obj: StreamOpenRequest): Uint8Array => { return encodeMessage(obj, StreamOpenRequest.codec()) } @@ -199,14 +593,74 @@ export interface StreamHandlerRequest { } export namespace StreamHandlerRequest { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'addr', codec: bytes }, - 2: { name: 'proto', codec: string, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.addr != null) { + writer.uint32(10) + writer.bytes(obj.addr) + } else { + throw new Error('Protocol error: required field "addr" was not found in object') + } + + if (obj.proto != null) { + for (const value of obj.proto) { + writer.uint32(18) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "proto" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.addr = reader.bytes() + break + case 2: + obj.proto = obj.proto ?? [] + obj.proto.push(reader.string()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.proto = obj.proto ?? [] + + if (obj.addr == null) { + throw new Error('Protocol error: value for required field "addr" was not found in protobuf') + } + + if (obj.proto == null) { + throw new Error('Protocol error: value for required field "proto" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: StreamHandlerRequest): Uint8ArrayList => { + export const encode = (obj: StreamHandlerRequest): Uint8Array => { return encodeMessage(obj, StreamHandlerRequest.codec()) } @@ -220,13 +674,55 @@ export interface ErrorResponse { } export namespace ErrorResponse { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'msg', codec: string } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.msg != null) { + writer.uint32(10) + writer.string(obj.msg) + } else { + throw new Error('Protocol error: required field "msg" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.msg = reader.string() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.msg == null) { + throw new Error('Protocol error: value for required field "msg" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: ErrorResponse): Uint8ArrayList => { + export const encode = (obj: ErrorResponse): Uint8Array => { return encodeMessage(obj, ErrorResponse.codec()) } @@ -242,15 +738,83 @@ export interface StreamInfo { } export namespace StreamInfo { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'peer', codec: bytes }, - 2: { name: 'addr', codec: bytes }, - 3: { name: 'proto', codec: string } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.peer != null) { + writer.uint32(10) + writer.bytes(obj.peer) + } else { + throw new Error('Protocol error: required field "peer" was not found in object') + } + + if (obj.addr != null) { + writer.uint32(18) + writer.bytes(obj.addr) + } else { + throw new Error('Protocol error: required field "addr" was not found in object') + } + + if (obj.proto != null) { + writer.uint32(26) + writer.string(obj.proto) + } else { + throw new Error('Protocol error: required field "proto" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.peer = reader.bytes() + break + case 2: + obj.addr = reader.bytes() + break + case 3: + obj.proto = reader.string() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.peer == null) { + throw new Error('Protocol error: value for required field "peer" was not found in protobuf') + } + + if (obj.addr == null) { + throw new Error('Protocol error: value for required field "addr" was not found in protobuf') + } + + if (obj.proto == null) { + throw new Error('Protocol error: value for required field "proto" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: StreamInfo): Uint8ArrayList => { + export const encode = (obj: StreamInfo): Uint8Array => { return encodeMessage(obj, StreamInfo.codec()) } @@ -296,23 +860,107 @@ export namespace DHTRequest { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: DHTRequest.Type.codec() }, - 2: { name: 'peer', codec: bytes, optional: true }, - 3: { name: 'cid', codec: bytes, optional: true }, - 4: { name: 'key', codec: bytes, optional: true }, - 5: { name: 'value', codec: bytes, optional: true }, - 6: { name: 'count', codec: int32, optional: true }, - 7: { name: 'timeout', codec: int64, optional: true } - }) - } - - export const encode = (obj: DHTRequest): Uint8ArrayList => { + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + DHTRequest.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.peer != null) { + writer.uint32(18) + writer.bytes(obj.peer) + } + + if (obj.cid != null) { + writer.uint32(26) + writer.bytes(obj.cid) + } + + if (obj.key != null) { + writer.uint32(34) + writer.bytes(obj.key) + } + + if (obj.value != null) { + writer.uint32(42) + writer.bytes(obj.value) + } + + if (obj.count != null) { + writer.uint32(48) + writer.int32(obj.count) + } + + if (obj.timeout != null) { + writer.uint32(56) + writer.int64(obj.timeout) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = DHTRequest.Type.codec().decode(reader) + break + case 2: + obj.peer = reader.bytes() + break + case 3: + obj.cid = reader.bytes() + break + case 4: + obj.key = reader.bytes() + break + case 5: + obj.value = reader.bytes() + break + case 6: + obj.count = reader.int32() + break + case 7: + obj.timeout = reader.int64() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + return obj + }) + } + + return _codec + } + + export const encode = (obj: DHTRequest): Uint8Array => { return encodeMessage(obj, DHTRequest.codec()) } @@ -342,19 +990,75 @@ export namespace DHTResponse { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: DHTResponse.Type.codec() }, - 2: { name: 'peer', codec: PeerInfo.codec(), optional: true }, - 3: { name: 'value', codec: bytes, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + DHTResponse.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.peer != null) { + writer.uint32(18) + PeerInfo.codec().encode(obj.peer, writer) + } + + if (obj.value != null) { + writer.uint32(26) + writer.bytes(obj.value) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = DHTResponse.Type.codec().decode(reader) + break + case 2: + obj.peer = PeerInfo.codec().decode(reader, reader.uint32()) + break + case 3: + obj.value = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: DHTResponse): Uint8ArrayList => { + export const encode = (obj: DHTResponse): Uint8Array => { return encodeMessage(obj, DHTResponse.codec()) } @@ -369,14 +1073,74 @@ export interface PeerInfo { } export namespace PeerInfo { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'id', codec: bytes }, - 2: { name: 'addrs', codec: bytes, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.id != null) { + writer.uint32(10) + writer.bytes(obj.id) + } else { + throw new Error('Protocol error: required field "id" was not found in object') + } + + if (obj.addrs != null) { + for (const value of obj.addrs) { + writer.uint32(18) + writer.bytes(value) + } + } else { + throw new Error('Protocol error: required field "addrs" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.id = reader.bytes() + break + case 2: + obj.addrs = obj.addrs ?? [] + obj.addrs.push(reader.bytes()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.addrs = obj.addrs ?? [] + + if (obj.id == null) { + throw new Error('Protocol error: value for required field "id" was not found in protobuf') + } + + if (obj.addrs == null) { + throw new Error('Protocol error: value for required field "addrs" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PeerInfo): Uint8ArrayList => { + export const encode = (obj: PeerInfo): Uint8Array => { return encodeMessage(obj, PeerInfo.codec()) } @@ -407,20 +1171,83 @@ export namespace ConnManagerRequest { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: ConnManagerRequest.Type.codec() }, - 2: { name: 'peer', codec: bytes, optional: true }, - 3: { name: 'tag', codec: string, optional: true }, - 4: { name: 'weight', codec: int64, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + ConnManagerRequest.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.peer != null) { + writer.uint32(18) + writer.bytes(obj.peer) + } + + if (obj.tag != null) { + writer.uint32(26) + writer.string(obj.tag) + } + + if (obj.weight != null) { + writer.uint32(32) + writer.int64(obj.weight) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = ConnManagerRequest.Type.codec().decode(reader) + break + case 2: + obj.peer = reader.bytes() + break + case 3: + obj.tag = reader.string() + break + case 4: + obj.weight = reader.int64() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: ConnManagerRequest): Uint8ArrayList => { + export const encode = (obj: ConnManagerRequest): Uint8Array => { return encodeMessage(obj, ConnManagerRequest.codec()) } @@ -434,13 +1261,55 @@ export interface DisconnectRequest { } export namespace DisconnectRequest { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'peer', codec: bytes } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.peer != null) { + writer.uint32(10) + writer.bytes(obj.peer) + } else { + throw new Error('Protocol error: required field "peer" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.peer = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.peer == null) { + throw new Error('Protocol error: value for required field "peer" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: DisconnectRequest): Uint8ArrayList => { + export const encode = (obj: DisconnectRequest): Uint8Array => { return encodeMessage(obj, DisconnectRequest.codec()) } @@ -472,19 +1341,75 @@ export namespace PSRequest { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: PSRequest.Type.codec() }, - 2: { name: 'topic', codec: string, optional: true }, - 3: { name: 'data', codec: bytes, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + PSRequest.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.topic != null) { + writer.uint32(18) + writer.string(obj.topic) + } + + if (obj.data != null) { + writer.uint32(26) + writer.bytes(obj.data) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = PSRequest.Type.codec().decode(reader) + break + case 2: + obj.topic = reader.string() + break + case 3: + obj.data = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PSRequest): Uint8ArrayList => { + export const encode = (obj: PSRequest): Uint8Array => { return encodeMessage(obj, PSRequest.codec()) } @@ -503,18 +1428,100 @@ export interface PSMessage { } export namespace PSMessage { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'from', codec: bytes, optional: true }, - 2: { name: 'data', codec: bytes, optional: true }, - 3: { name: 'seqno', codec: bytes, optional: true }, - 4: { name: 'topicIDs', codec: string, repeats: true }, - 5: { name: 'signature', codec: bytes, optional: true }, - 6: { name: 'key', codec: bytes, optional: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.from != null) { + writer.uint32(10) + writer.bytes(obj.from) + } + + if (obj.data != null) { + writer.uint32(18) + writer.bytes(obj.data) + } + + if (obj.seqno != null) { + writer.uint32(26) + writer.bytes(obj.seqno) + } + + if (obj.topicIDs != null) { + for (const value of obj.topicIDs) { + writer.uint32(34) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "topicIDs" was not found in object') + } + + if (obj.signature != null) { + writer.uint32(42) + writer.bytes(obj.signature) + } + + if (obj.key != null) { + writer.uint32(50) + writer.bytes(obj.key) + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.from = reader.bytes() + break + case 2: + obj.data = reader.bytes() + break + case 3: + obj.seqno = reader.bytes() + break + case 4: + obj.topicIDs = obj.topicIDs ?? [] + obj.topicIDs.push(reader.string()) + break + case 5: + obj.signature = reader.bytes() + break + case 6: + obj.key = reader.bytes() + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.topicIDs = obj.topicIDs ?? [] + + if (obj.topicIDs == null) { + throw new Error('Protocol error: value for required field "topicIDs" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PSMessage): Uint8ArrayList => { + export const encode = (obj: PSMessage): Uint8Array => { return encodeMessage(obj, PSMessage.codec()) } @@ -529,14 +1536,78 @@ export interface PSResponse { } export namespace PSResponse { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'topics', codec: string, repeats: true }, - 2: { name: 'peerIDs', codec: bytes, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.topics != null) { + for (const value of obj.topics) { + writer.uint32(10) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "topics" was not found in object') + } + + if (obj.peerIDs != null) { + for (const value of obj.peerIDs) { + writer.uint32(18) + writer.bytes(value) + } + } else { + throw new Error('Protocol error: required field "peerIDs" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.topics = obj.topics ?? [] + obj.topics.push(reader.string()) + break + case 2: + obj.peerIDs = obj.peerIDs ?? [] + obj.peerIDs.push(reader.bytes()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.topics = obj.topics ?? [] + obj.peerIDs = obj.peerIDs ?? [] + + if (obj.topics == null) { + throw new Error('Protocol error: value for required field "topics" was not found in protobuf') + } + + if (obj.peerIDs == null) { + throw new Error('Protocol error: value for required field "peerIDs" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PSResponse): Uint8ArrayList => { + export const encode = (obj: PSResponse): Uint8Array => { return encodeMessage(obj, PSResponse.codec()) } @@ -564,19 +1635,86 @@ export namespace PeerstoreRequest { export namespace Type { export const codec = () => { - return enumeration(__TypeValues) + return enumeration(__TypeValues) } } + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'type', codec: PeerstoreRequest.Type.codec() }, - 2: { name: 'id', codec: bytes, optional: true }, - 3: { name: 'protos', codec: string, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.type != null) { + writer.uint32(8) + PeerstoreRequest.Type.codec().encode(obj.type, writer) + } else { + throw new Error('Protocol error: required field "type" was not found in object') + } + + if (obj.id != null) { + writer.uint32(18) + writer.bytes(obj.id) + } + + if (obj.protos != null) { + for (const value of obj.protos) { + writer.uint32(26) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "protos" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.type = PeerstoreRequest.Type.codec().decode(reader) + break + case 2: + obj.id = reader.bytes() + break + case 3: + obj.protos = obj.protos ?? [] + obj.protos.push(reader.string()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.protos = obj.protos ?? [] + + if (obj.type == null) { + throw new Error('Protocol error: value for required field "type" was not found in protobuf') + } + + if (obj.protos == null) { + throw new Error('Protocol error: value for required field "protos" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PeerstoreRequest): Uint8ArrayList => { + export const encode = (obj: PeerstoreRequest): Uint8Array => { return encodeMessage(obj, PeerstoreRequest.codec()) } @@ -591,14 +1729,68 @@ export interface PeerstoreResponse { } export namespace PeerstoreResponse { + let _codec: Codec + export const codec = (): Codec => { - return message({ - 1: { name: 'peer', codec: PeerInfo.codec(), optional: true }, - 2: { name: 'protos', codec: string, repeats: true } - }) + if (_codec == null) { + _codec = message((obj, writer, opts = {}) => { + if (opts.lengthDelimited !== false) { + writer.fork() + } + + if (obj.peer != null) { + writer.uint32(10) + PeerInfo.codec().encode(obj.peer, writer) + } + + if (obj.protos != null) { + for (const value of obj.protos) { + writer.uint32(18) + writer.string(value) + } + } else { + throw new Error('Protocol error: required field "protos" was not found in object') + } + + if (opts.lengthDelimited !== false) { + writer.ldelim() + } + }, (reader, length) => { + const obj: any = {} + + const end = length == null ? reader.len : reader.pos + length + + while (reader.pos < end) { + const tag = reader.uint32() + + switch (tag >>> 3) { + case 1: + obj.peer = PeerInfo.codec().decode(reader, reader.uint32()) + break + case 2: + obj.protos = obj.protos ?? [] + obj.protos.push(reader.string()) + break + default: + reader.skipType(tag & 7) + break + } + } + + obj.protos = obj.protos ?? [] + + if (obj.protos == null) { + throw new Error('Protocol error: value for required field "protos" was not found in protobuf') + } + + return obj + }) + } + + return _codec } - export const encode = (obj: PeerstoreResponse): Uint8ArrayList => { + export const encode = (obj: PeerstoreResponse): Uint8Array => { return encodeMessage(obj, PeerstoreResponse.codec()) } diff --git a/packages/libp2p-daemon-server/package.json b/packages/libp2p-daemon-server/package.json index 98a11f82..957fb7a7 100644 --- a/packages/libp2p-daemon-server/package.json +++ b/packages/libp2p-daemon-server/package.json @@ -139,7 +139,7 @@ }, "dependencies": { "@libp2p/daemon-protocol": "^2.0.0", - "@libp2p/interface-connection": "^2.0.0", + "@libp2p/interface-connection": "^3.0.1", "@libp2p/interface-dht": "^1.0.0", "@libp2p/interface-peer-id": "^1.0.2", "@libp2p/interface-registrar": "^2.0.1", diff --git a/packages/libp2p-daemon-server/src/index.ts b/packages/libp2p-daemon-server/src/index.ts index 1b788bf6..7c3e78ee 100644 --- a/packages/libp2p-daemon-server/src/index.ts +++ b/packages/libp2p-daemon-server/src/index.ts @@ -443,6 +443,11 @@ export class Server implements Libp2pServer { await pipe( stream, response.connection, + async function * (source) { + for await (const list of source) { + yield * list + } + }, stream ) // Exit the iterator, no more requests can come through diff --git a/packages/libp2p-daemon-server/src/pubsub.ts b/packages/libp2p-daemon-server/src/pubsub.ts index f7f7773b..c1f38f91 100644 --- a/packages/libp2p-daemon-server/src/pubsub.ts +++ b/packages/libp2p-daemon-server/src/pubsub.ts @@ -50,14 +50,21 @@ export class PubSubOperations { return } - onMessage.push(PSMessage.encode({ - from: msg.from.toBytes(), - data: msg.data, - seqno: msg.sequenceNumber == null ? undefined : uint8ArrayFromString(msg.sequenceNumber.toString(16).padStart(16, '0'), 'base16'), - topicIDs: [msg.topic], - signature: msg.signature, - key: msg.key - }).subarray()) + if (msg.type === 'signed') { + onMessage.push(PSMessage.encode({ + from: msg.from.toBytes(), + data: msg.data, + seqno: msg.sequenceNumber == null ? undefined : uint8ArrayFromString(msg.sequenceNumber.toString(16).padStart(16, '0'), 'base16'), + topicIDs: [msg.topic], + signature: msg.signature, + key: msg.key + }).subarray()) + } else { + onMessage.push(PSMessage.encode({ + data: msg.data, + topicIDs: [msg.topic] + }).subarray()) + } }) yield OkResponse()