Skip to content
23 changes: 12 additions & 11 deletions libp2p/multiaddress.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{.push raises: [].}
{.push public.}

import pkg/chronos, chronicles
import pkg/[chronos, chronicles, results]
import std/[nativesockets, net, hashes]
import tables, strutils, sets
import
Expand All @@ -25,8 +25,8 @@ import
protobuf/minprotobuf,
errors,
utility
import stew/[base58, base32, endians2, results]
export results, minprotobuf, vbuffer, utility
import stew/[base58, base32, endians2]
export results, minprotobuf, vbuffer, errors, utility

logScope:
topics = "libp2p multiaddress"
Expand Down Expand Up @@ -71,6 +71,9 @@ type
tcpProtocol
udpProtocol

func maErr*(msg: string): ref MaError =
(ref MaError)(msg: msg)

const
# These are needed in order to avoid an ambiguity error stemming from
# some cint constants with the same name defined in the posix modules
Expand Down Expand Up @@ -970,23 +973,21 @@ proc append*(m1: var MultiAddress, m2: MultiAddress): MaResult[void] =
else:
ok()

proc `&`*(m1, m2: MultiAddress): MultiAddress {.raises: [LPError].} =
proc `&`*(m1, m2: MultiAddress): MultiAddress {.raises: [MaError].} =
## Concatenates two addresses ``m1`` and ``m2``, and returns result.
##
## This procedure performs validation of concatenated result and can raise
## exception on error.
##

concat(m1, m2).tryGet()
concat(m1, m2).valueOr:
raise maErr error

proc `&=`*(m1: var MultiAddress, m2: MultiAddress) {.raises: [LPError].} =
proc `&=`*(m1: var MultiAddress, m2: MultiAddress) {.raises: [MaError].} =
## Concatenates two addresses ``m1`` and ``m2``.
##
## This procedure performs validation of concatenated result and can raise
## exception on error.
##

m1.append(m2).tryGet()
m1.append(m2).isOkOr:
raise maErr error

proc `==`*(m1: var MultiAddress, m2: MultiAddress): bool =
## Check of two MultiAddress are equal
Expand Down