This repository was archived by the owner on Jan 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmix.nim
More file actions
51 lines (44 loc) · 1.38 KB
/
mix.nim
File metadata and controls
51 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright (c) Logos
import results
import chronos
import libp2p
import ./mix/[mix_protocol, mix_node, entry_connection, exit_layer]
export results
export toConnection
export MixProtocolID
export MixProtocol
export initializeMixNodes
export getMixPubInfoByIndex
export writeMixPubInfoToFile
export writeMixNodeInfoToFile
export getMixNodeInfo
export `new`
export init
export getMaxMessageSizeForCodec
export deleteNodeInfoFolder
export deletePubInfoFolder
export MixDestination
export MixParameters
export destReadBehaviorCb
export registerDestReadBehavior
export MixNodes
export initMixMultiAddrByIndex
when defined(mix_experimental_exit_is_destination):
export exitNode
export forwardToAddr
proc readLp*(maxSize: int): destReadBehaviorCb =
## create callback to read length prefixed msg, with the length encoded as a varint
return proc(
conn: Connection
): Future[seq[byte]] {.async: (raises: [CancelledError, LPStreamError]).} =
await conn.readLp(maxSize)
proc readExactly*(nBytes: int): destReadBehaviorCb =
## create callback that waits for `nbytes` to be available, then read
## them and return them
return proc(
conn: Connection
): Future[seq[byte]] {.async: (raises: [CancelledError, LPStreamError]).} =
let buf = newSeqUninitialized[byte](nBytes)
await conn.readExactly(addr buf[0], nBytes)
return buf