diff --git a/packages/libp2p-daemon-client/package.json b/packages/libp2p-daemon-client/package.json index a302ce60..30237836 100644 --- a/packages/libp2p-daemon-client/package.json +++ b/packages/libp2p-daemon-client/package.json @@ -150,7 +150,7 @@ "@libp2p/daemon-server": "^2.0.0", "@libp2p/interface-compliance-tests": "^3.0.1", "@libp2p/interface-dht": "^1.0.0", - "@libp2p/interface-mocks": "^2.0.1", + "@libp2p/interface-mocks": "^3.0.2", "@libp2p/interface-peer-store": "^1.0.0", "@libp2p/interface-pubsub": "^1.0.1", "@libp2p/peer-id-factory": "^1.0.9", diff --git a/packages/libp2p-daemon-protocol/package.json b/packages/libp2p-daemon-protocol/package.json index 161714fc..602577d5 100644 --- a/packages/libp2p-daemon-protocol/package.json +++ b/packages/libp2p-daemon-protocol/package.json @@ -159,10 +159,11 @@ "dependencies": { "@libp2p/interface-transport": "^1.0.0", "it-handshake": "^4.0.0", - "protons-runtime": "^1.0.4" + "protons-runtime": "^2.0.2", + "uint8arraylist": "^2.0.0" }, "devDependencies": { "aegir": "^37.2.0", - "protons": "^3.0.4" + "protons": "^4.0.1" } } diff --git a/packages/libp2p-daemon-protocol/src/index.ts b/packages/libp2p-daemon-protocol/src/index.ts index 7b4e7a16..3c0a9583 100644 --- a/packages/libp2p-daemon-protocol/src/index.ts +++ b/packages/libp2p-daemon-protocol/src/index.ts @@ -3,6 +3,7 @@ import { enumeration, encodeMessage, decodeMessage, message, bytes, int64, string, int32 } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Request { type: Request.Type @@ -63,11 +64,11 @@ export namespace Request { }) } - export const encode = (obj: Request): Uint8Array => { + export const encode = (obj: Request): Uint8ArrayList => { return encodeMessage(obj, Request.codec()) } - export const decode = (buf: Uint8Array): Request => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Request => { return decodeMessage(buf, Request.codec()) } } @@ -113,11 +114,11 @@ export namespace Response { }) } - export const encode = (obj: Response): Uint8Array => { + export const encode = (obj: Response): Uint8ArrayList => { return encodeMessage(obj, Response.codec()) } - export const decode = (buf: Uint8Array): Response => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Response => { return decodeMessage(buf, Response.codec()) } } @@ -135,11 +136,11 @@ export namespace IdentifyResponse { }) } - export const encode = (obj: IdentifyResponse): Uint8Array => { + export const encode = (obj: IdentifyResponse): Uint8ArrayList => { return encodeMessage(obj, IdentifyResponse.codec()) } - export const decode = (buf: Uint8Array): IdentifyResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): IdentifyResponse => { return decodeMessage(buf, IdentifyResponse.codec()) } } @@ -159,11 +160,11 @@ export namespace ConnectRequest { }) } - export const encode = (obj: ConnectRequest): Uint8Array => { + export const encode = (obj: ConnectRequest): Uint8ArrayList => { return encodeMessage(obj, ConnectRequest.codec()) } - export const decode = (buf: Uint8Array): ConnectRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ConnectRequest => { return decodeMessage(buf, ConnectRequest.codec()) } } @@ -183,11 +184,11 @@ export namespace StreamOpenRequest { }) } - export const encode = (obj: StreamOpenRequest): Uint8Array => { + export const encode = (obj: StreamOpenRequest): Uint8ArrayList => { return encodeMessage(obj, StreamOpenRequest.codec()) } - export const decode = (buf: Uint8Array): StreamOpenRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamOpenRequest => { return decodeMessage(buf, StreamOpenRequest.codec()) } } @@ -205,11 +206,11 @@ export namespace StreamHandlerRequest { }) } - export const encode = (obj: StreamHandlerRequest): Uint8Array => { + export const encode = (obj: StreamHandlerRequest): Uint8ArrayList => { return encodeMessage(obj, StreamHandlerRequest.codec()) } - export const decode = (buf: Uint8Array): StreamHandlerRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamHandlerRequest => { return decodeMessage(buf, StreamHandlerRequest.codec()) } } @@ -225,11 +226,11 @@ export namespace ErrorResponse { }) } - export const encode = (obj: ErrorResponse): Uint8Array => { + export const encode = (obj: ErrorResponse): Uint8ArrayList => { return encodeMessage(obj, ErrorResponse.codec()) } - export const decode = (buf: Uint8Array): ErrorResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ErrorResponse => { return decodeMessage(buf, ErrorResponse.codec()) } } @@ -249,11 +250,11 @@ export namespace StreamInfo { }) } - export const encode = (obj: StreamInfo): Uint8Array => { + export const encode = (obj: StreamInfo): Uint8ArrayList => { return encodeMessage(obj, StreamInfo.codec()) } - export const decode = (buf: Uint8Array): StreamInfo => { + export const decode = (buf: Uint8Array | Uint8ArrayList): StreamInfo => { return decodeMessage(buf, StreamInfo.codec()) } } @@ -311,11 +312,11 @@ export namespace DHTRequest { }) } - export const encode = (obj: DHTRequest): Uint8Array => { + export const encode = (obj: DHTRequest): Uint8ArrayList => { return encodeMessage(obj, DHTRequest.codec()) } - export const decode = (buf: Uint8Array): DHTRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DHTRequest => { return decodeMessage(buf, DHTRequest.codec()) } } @@ -353,11 +354,11 @@ export namespace DHTResponse { }) } - export const encode = (obj: DHTResponse): Uint8Array => { + export const encode = (obj: DHTResponse): Uint8ArrayList => { return encodeMessage(obj, DHTResponse.codec()) } - export const decode = (buf: Uint8Array): DHTResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DHTResponse => { return decodeMessage(buf, DHTResponse.codec()) } } @@ -375,11 +376,11 @@ export namespace PeerInfo { }) } - export const encode = (obj: PeerInfo): Uint8Array => { + export const encode = (obj: PeerInfo): Uint8ArrayList => { return encodeMessage(obj, PeerInfo.codec()) } - export const decode = (buf: Uint8Array): PeerInfo => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { return decodeMessage(buf, PeerInfo.codec()) } } @@ -419,11 +420,11 @@ export namespace ConnManagerRequest { }) } - export const encode = (obj: ConnManagerRequest): Uint8Array => { + export const encode = (obj: ConnManagerRequest): Uint8ArrayList => { return encodeMessage(obj, ConnManagerRequest.codec()) } - export const decode = (buf: Uint8Array): ConnManagerRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): ConnManagerRequest => { return decodeMessage(buf, ConnManagerRequest.codec()) } } @@ -439,11 +440,11 @@ export namespace DisconnectRequest { }) } - export const encode = (obj: DisconnectRequest): Uint8Array => { + export const encode = (obj: DisconnectRequest): Uint8ArrayList => { return encodeMessage(obj, DisconnectRequest.codec()) } - export const decode = (buf: Uint8Array): DisconnectRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): DisconnectRequest => { return decodeMessage(buf, DisconnectRequest.codec()) } } @@ -483,11 +484,11 @@ export namespace PSRequest { }) } - export const encode = (obj: PSRequest): Uint8Array => { + export const encode = (obj: PSRequest): Uint8ArrayList => { return encodeMessage(obj, PSRequest.codec()) } - export const decode = (buf: Uint8Array): PSRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSRequest => { return decodeMessage(buf, PSRequest.codec()) } } @@ -513,11 +514,11 @@ export namespace PSMessage { }) } - export const encode = (obj: PSMessage): Uint8Array => { + export const encode = (obj: PSMessage): Uint8ArrayList => { return encodeMessage(obj, PSMessage.codec()) } - export const decode = (buf: Uint8Array): PSMessage => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSMessage => { return decodeMessage(buf, PSMessage.codec()) } } @@ -535,11 +536,11 @@ export namespace PSResponse { }) } - export const encode = (obj: PSResponse): Uint8Array => { + export const encode = (obj: PSResponse): Uint8ArrayList => { return encodeMessage(obj, PSResponse.codec()) } - export const decode = (buf: Uint8Array): PSResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PSResponse => { return decodeMessage(buf, PSResponse.codec()) } } @@ -575,11 +576,11 @@ export namespace PeerstoreRequest { }) } - export const encode = (obj: PeerstoreRequest): Uint8Array => { + export const encode = (obj: PeerstoreRequest): Uint8ArrayList => { return encodeMessage(obj, PeerstoreRequest.codec()) } - export const decode = (buf: Uint8Array): PeerstoreRequest => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreRequest => { return decodeMessage(buf, PeerstoreRequest.codec()) } } @@ -597,11 +598,11 @@ export namespace PeerstoreResponse { }) } - export const encode = (obj: PeerstoreResponse): Uint8Array => { + export const encode = (obj: PeerstoreResponse): Uint8ArrayList => { return encodeMessage(obj, PeerstoreResponse.codec()) } - export const decode = (buf: Uint8Array): PeerstoreResponse => { + export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreResponse => { return decodeMessage(buf, PeerstoreResponse.codec()) } } diff --git a/packages/libp2p-daemon-protocol/src/stream-handler.ts b/packages/libp2p-daemon-protocol/src/stream-handler.ts index b794a9cd..46d73c2d 100644 --- a/packages/libp2p-daemon-protocol/src/stream-handler.ts +++ b/packages/libp2p-daemon-protocol/src/stream-handler.ts @@ -3,6 +3,7 @@ import { handshake } from 'it-handshake' import { logger } from '@libp2p/logger' import type { Duplex, Source } from 'it-stream-types' import type { Handshake } from 'it-handshake' +import type { Uint8ArrayList } from 'uint8arraylist' const log = logger('libp2p:daemon-protocol:stream-handler') @@ -14,7 +15,7 @@ export interface StreamHandlerOptions { export class StreamHandler { private readonly stream: Duplex private readonly shake: Handshake - public decoder: Source + public decoder: Source /** * Create a stream handler for connection */ @@ -41,10 +42,10 @@ export class StreamHandler { await this.close() } - write (msg: Uint8Array) { + write (msg: Uint8Array | Uint8ArrayList) { log('write message') this.shake.write( - lp.encode.single(msg).slice() + lp.encode.single(msg).subarray() ) } diff --git a/packages/libp2p-daemon-server/package.json b/packages/libp2p-daemon-server/package.json index f1847d89..fbff828e 100644 --- a/packages/libp2p-daemon-server/package.json +++ b/packages/libp2p-daemon-server/package.json @@ -150,7 +150,7 @@ "@libp2p/tcp": "^3.0.0", "@multiformats/multiaddr": "^10.1.8", "it-drain": "^1.0.5", - "it-length-prefixed": "^7.0.1", + "it-length-prefixed": "^8.0.2", "it-pipe": "^2.0.3", "it-pushable": "^3.0.0", "multiformats": "^9.6.4", diff --git a/packages/libp2p-daemon-server/src/pubsub.ts b/packages/libp2p-daemon-server/src/pubsub.ts index efdfde62..f7f7773b 100644 --- a/packages/libp2p-daemon-server/src/pubsub.ts +++ b/packages/libp2p-daemon-server/src/pubsub.ts @@ -57,7 +57,7 @@ export class PubSubOperations { topicIDs: [msg.topic], signature: msg.signature, key: msg.key - })) + }).subarray()) }) yield OkResponse() diff --git a/packages/libp2p-daemon-server/src/responses.ts b/packages/libp2p-daemon-server/src/responses.ts index fe173b02..96b1b9fb 100644 --- a/packages/libp2p-daemon-server/src/responses.ts +++ b/packages/libp2p-daemon-server/src/responses.ts @@ -8,7 +8,7 @@ export function OkResponse (data?: Partial): Uint8Array { type: Response.Type.OK, peers: [], ...data - }) + }).subarray() } /** @@ -21,5 +21,5 @@ export function ErrorResponse (err: Error): Uint8Array { msg: err.message }, peers: [] - }) + }).subarray() }