mirror of
https://github.com/vacp2p/mix.git
synced 2026-01-08 04:53:55 -05:00
refactor: remove entry_connection_callbacks and gossipsub related procs (#70)
This commit is contained in:
@@ -9,6 +9,7 @@ import
|
||||
protocols/pubsub/pubsubpeer,
|
||||
protocols/pubsub/rpc/messages,
|
||||
]
|
||||
import ./poc_gossipsub_utils
|
||||
|
||||
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import
|
||||
protocols/pubsub/pubsubpeer,
|
||||
protocols/pubsub/rpc/messages,
|
||||
]
|
||||
import ./poc_gossipsub_utils
|
||||
|
||||
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
||||
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
# TODO: this file should likely become mix.nim in the root of the project
|
||||
|
||||
import chronos, chronicles, results
|
||||
import std/[sequtils, sets]
|
||||
import libp2p/[multiaddress, protocols/pubsub/pubsubpeer, switch]
|
||||
import ./[entry_connection, mix_protocol]
|
||||
import libp2p/[protocols/pubsub/pubsubpeer, switch]
|
||||
|
||||
const D* = 4 # No. of peers to forward to
|
||||
|
||||
proc toConnection*(
|
||||
srcMix: MixProtocol,
|
||||
destPeerId: PeerId,
|
||||
destForwardToAddr: Opt[MultiAddress],
|
||||
codec: string,
|
||||
): Connection {.gcsafe, raises: [].} =
|
||||
MixEntryConnection.new(srcMix, destPeerId, destForwardToAddr, codec)
|
||||
|
||||
proc mixPeerSelection*(
|
||||
allPeers: HashSet[PubSubPeer],
|
||||
directPeers: HashSet[PubSubPeer],
|
||||
4
mix.nim
4
mix.nim
@@ -1,11 +1,9 @@
|
||||
import results
|
||||
import ./mix/[entry_connection_callbacks, mix_protocol, mix_node]
|
||||
import ./mix/[mix_protocol, mix_node, entry_connection]
|
||||
|
||||
export results
|
||||
|
||||
export D
|
||||
export toConnection
|
||||
export mixPeerSelection
|
||||
export MixProtocolID
|
||||
export MixProtocol
|
||||
export initializeMixNodes
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import hashes, chronos, stew/byteutils, results
|
||||
import hashes, chronos, stew/byteutils, results, chronicles
|
||||
import libp2p/stream/connection
|
||||
import ./mix_protocol
|
||||
from fragmentation import dataSize
|
||||
@@ -138,3 +138,11 @@ proc new*(
|
||||
return
|
||||
|
||||
T.new(srcMix, destPeerId, destForwardToAddr, codec, sendDialerFunc)
|
||||
|
||||
proc toConnection*(
|
||||
srcMix: MixProtocol,
|
||||
destPeerId: PeerId,
|
||||
destForwardToAddr: Opt[MultiAddress],
|
||||
codec: string,
|
||||
): Connection {.gcsafe, raises: [].} =
|
||||
MixEntryConnection.new(srcMix, destPeerId, destForwardToAddr, codec)
|
||||
|
||||
@@ -2,7 +2,7 @@ import results, strutils
|
||||
import stew/base58
|
||||
import ./config
|
||||
|
||||
const multiAddrLen = 39
|
||||
const peerIdByteLen = 39
|
||||
|
||||
proc bytesToUInt16*(data: openArray[byte]): Result[uint16, string] =
|
||||
if len(data) != 2:
|
||||
@@ -37,8 +37,8 @@ proc extractPeerId(parts: seq[string], index: int): Result[seq[byte], string] =
|
||||
return err("Peer ID must be exactly 53 characters")
|
||||
try:
|
||||
let peerIdBytes = Base58.decode(peerIdBase58)
|
||||
if peerIdBytes.len != multiAddrLen:
|
||||
return err("Peer ID must be exactly " & $multiAddrLen & " bytes")
|
||||
if peerIdBytes.len != peerIdByteLen:
|
||||
return err("Peer ID must be exactly " & $peerIdByteLen & " bytes")
|
||||
return ok(peerIdBytes)
|
||||
except Base58Error:
|
||||
return err("Invalid Peer ID")
|
||||
@@ -135,9 +135,9 @@ proc bytesToMultiAddr*(bytes: openArray[byte]): Result[string, string] =
|
||||
|
||||
let peerId1 = "/p2p/" & Base58.encode(bytes[7 ..< 46])
|
||||
|
||||
let peerId2Bytes = bytes[7 + multiAddrLen ..< 7 + (multiAddrLen * 2)]
|
||||
let peerId2Bytes = bytes[7 + peerIdByteLen ..< 7 + (peerIdByteLen * 2)]
|
||||
let peerId2 =
|
||||
if peerId2Bytes != newSeq[byte](multiAddrLen):
|
||||
if peerId2Bytes != newSeq[byte](peerIdByteLen):
|
||||
"/p2p-circuit/p2p/" & Base58.encode(peerId2Bytes)
|
||||
else:
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user