Skip to content

Commit

Permalink
deps: update uint8arraylist and protons deps (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Jul 31, 2022
1 parent 345e663 commit 34a8334
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/libp2p-daemon-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
73 changes: 37 additions & 36 deletions packages/libp2p-daemon-protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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())
}
}
7 changes: 4 additions & 3 deletions packages/libp2p-daemon-protocol/src/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -14,7 +15,7 @@ export interface StreamHandlerOptions {
export class StreamHandler {
private readonly stream: Duplex<Uint8Array>
private readonly shake: Handshake
public decoder: Source<Uint8Array>
public decoder: Source<Uint8ArrayList>
/**
* Create a stream handler for connection
*/
Expand All @@ -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()
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-server/src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PubSubOperations {
topicIDs: [msg.topic],
signature: msg.signature,
key: msg.key
}))
}).subarray())
})

yield OkResponse()
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-server/src/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function OkResponse (data?: Partial<Response>): Uint8Array {
type: Response.Type.OK,
peers: [],
...data
})
}).subarray()
}

/**
Expand All @@ -21,5 +21,5 @@ export function ErrorResponse (err: Error): Uint8Array {
msg: err.message
},
peers: []
})
}).subarray()
}

0 comments on commit 34a8334

Please sign in to comment.