Skip to content

Commit 90e42cf

Browse files
committed
srv: added NodeToNodeV_15
Bumped version, to mark the SRV support.
1 parent 104e370 commit 90e42cf

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

docs/network-spec/miniprotocols.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,7 @@ \section{Node-to-node protocol}
21812181
\begin{tabular}{l|l}
21822182
\header{version} & \header{description} \\\hline
21832183
\texttt{NodeToNodeV\_14} & No changes, identifies Plomin HF nodes mandatory on mainnet as of 2025.01.29\\
2184+
\texttt{NodeToNodeV\_15} & No changes, identifies nodes which support SRV records\\
21842185
\end{tabular}
21852186
\caption{Node-to-node protocol versions}
21862187
\label{table:node-to-node-protocol-versions}

ouroboros-network-api/src/Ouroboros/Network/NodeToNode/Version.hs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ data NodeToNodeVersion =
6868
-- peer sharing server side and can not reply to requests.
6969
NodeToNodeV_14
7070
-- ^ Plomin HF, mandatory on mainnet as of 2025.01.29
71+
| NodeToNodeV_15
72+
-- ^ SRV support
7173
deriving (Eq, Ord, Enum, Bounded, Show, Generic, NFData)
7274

7375
nodeToNodeVersionCodec :: CodecCBORTerm (Text, Maybe Int) NodeToNodeVersion
7476
nodeToNodeVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
7577
where
7678
encodeTerm NodeToNodeV_14 = CBOR.TInt 14
79+
encodeTerm NodeToNodeV_15 = CBOR.TInt 15
7780

7881
decodeTerm (CBOR.TInt 14) = Right NodeToNodeV_14
82+
decodeTerm (CBOR.TInt 15) = Right NodeToNodeV_15
7983
decodeTerm (CBOR.TInt n) = Left ( T.pack "decode NodeToNodeVersion: unknown tag: "
8084
<> T.pack (show n)
8185
, Just n
@@ -146,14 +150,14 @@ instance Queryable NodeToNodeVersionData where
146150

147151
nodeToNodeCodecCBORTerm :: NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
148152
nodeToNodeCodecCBORTerm =
149-
\case
150-
NodeToNodeV_14 -> v14
151-
153+
\case
154+
NodeToNodeV_14 -> codec
155+
NodeToNodeV_15 -> codec
152156
where
153-
v14 = CodecCBORTerm { encodeTerm = encodeTerm14, decodeTerm = decodeTerm14 }
157+
codec = CodecCBORTerm { encodeTerm = encodeTerm, decodeTerm = decodeTerm }
154158

155-
encodeTerm14 :: NodeToNodeVersionData -> CBOR.Term
156-
encodeTerm14 NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing, query }
159+
encodeTerm :: NodeToNodeVersionData -> CBOR.Term
160+
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing, query }
157161
= CBOR.TList
158162
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
159163
, CBOR.TBool (case diffusionMode of
@@ -165,8 +169,8 @@ nodeToNodeCodecCBORTerm =
165169
, CBOR.TBool query
166170
]
167171

168-
decodeTerm14 :: CBOR.Term -> Either Text NodeToNodeVersionData
169-
decodeTerm14 (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt peerSharing, CBOR.TBool query])
172+
decodeTerm :: CBOR.Term -> Either Text NodeToNodeVersionData
173+
decodeTerm (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt peerSharing, CBOR.TBool query])
170174
| x >= 0
171175
, x <= 0xffffffff
172176
, Just ps <- case peerSharing of
@@ -186,7 +190,7 @@ nodeToNodeCodecCBORTerm =
186190
= Left $ T.pack $ "networkMagic out of bound: " <> show x
187191
| otherwise -- peerSharing < 0 || peerSharing > 1
188192
= Left $ T.pack $ "peerSharing is out of bound: " <> show peerSharing
189-
decodeTerm14 t
193+
decodeTerm t
190194
= Left $ T.pack $ "unknown encoding: " ++ show t
191195

192196

ouroboros-network-api/src/Ouroboros/Network/PeerSelection/PeerSharing/Codec.hs

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,39 @@ decodePortNumber = fromIntegral <$> CBOR.decodeWord16
2828
-- /Invariant:/ not a unix socket address type.
2929
---
3030
encodeRemoteAddress :: NodeToNodeVersion -> SockAddr -> CBOR.Encoding
31-
encodeRemoteAddress =
32-
\case
33-
NodeToNodeV_14 -> sockAddr
34-
35-
where
36-
sockAddr = \case
37-
SockAddrInet pn w -> CBOR.encodeListLen 3
38-
<> CBOR.encodeWord 0
39-
<> CBOR.encodeWord32 w
40-
<> encodePortNumber pn
41-
SockAddrInet6 pn _ (w1, w2, w3, w4) _ -> CBOR.encodeListLen 6
42-
<> CBOR.encodeWord 1
43-
<> CBOR.encodeWord32 w1
44-
<> CBOR.encodeWord32 w2
45-
<> CBOR.encodeWord32 w3
46-
<> CBOR.encodeWord32 w4
47-
<> encodePortNumber pn
48-
SockAddrUnix _ -> error "Should never be encoding a SockAddrUnix!"
31+
encodeRemoteAddress _ = \case
32+
SockAddrInet pn w -> CBOR.encodeListLen 3
33+
<> CBOR.encodeWord 0
34+
<> CBOR.encodeWord32 w
35+
<> encodePortNumber pn
36+
SockAddrInet6 pn _ (w1, w2, w3, w4) _ -> CBOR.encodeListLen 6
37+
<> CBOR.encodeWord 1
38+
<> CBOR.encodeWord32 w1
39+
<> CBOR.encodeWord32 w2
40+
<> CBOR.encodeWord32 w3
41+
<> CBOR.encodeWord32 w4
42+
<> encodePortNumber pn
43+
SockAddrUnix _ -> error "Should never be encoding a SockAddrUnix!"
4944

5045
-- | This decoder should be faithful to the PeerSharing
5146
-- CDDL Specification.
5247
--
5348
-- See the network design document for more details
5449
--
5550
decodeRemoteAddress :: NodeToNodeVersion -> CBOR.Decoder s SockAddr
56-
decodeRemoteAddress =
57-
\case
58-
NodeToNodeV_14 -> decoder14
59-
60-
where
61-
decoder14 = do
62-
_ <- CBOR.decodeListLen
63-
tok <- CBOR.decodeWord
64-
case tok of
65-
0 -> do
66-
w <- CBOR.decodeWord32
67-
pn <- decodePortNumber
68-
return (SockAddrInet pn w)
69-
1 -> do
70-
w1 <- CBOR.decodeWord32
71-
w2 <- CBOR.decodeWord32
72-
w3 <- CBOR.decodeWord32
73-
w4 <- CBOR.decodeWord32
74-
pn <- decodePortNumber
75-
return (SockAddrInet6 pn 0 (w1, w2, w3, w4) 0)
76-
_ -> fail ("Serialise.decode.SockAddr unexpected tok " ++ show tok)
51+
decodeRemoteAddress _ = do
52+
_ <- CBOR.decodeListLen
53+
tok <- CBOR.decodeWord
54+
case tok of
55+
0 -> do
56+
w <- CBOR.decodeWord32
57+
pn <- decodePortNumber
58+
return (SockAddrInet pn w)
59+
1 -> do
60+
w1 <- CBOR.decodeWord32
61+
w2 <- CBOR.decodeWord32
62+
w3 <- CBOR.decodeWord32
63+
w4 <- CBOR.decodeWord32
64+
pn <- decodePortNumber
65+
return (SockAddrInet6 pn 0 (w1, w2, w3, w4) 0)
66+
_ -> fail ("Serialise.decode.SockAddr unexpected tok " ++ show tok)

ouroboros-network/orphan-instances/Ouroboros/Network/OrphanInstances.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ instance FromJSON AcceptedConnectionsLimit where
226226
instance FromJSON NodeToNodeVersion where
227227
parseJSON = \case
228228
Number 14 -> pure NodeToNodeV_14
229+
Number 15 -> pure NodeToNodeV_15
229230
Number x -> fail $ "FromJSON.NodeToNodeVersion: unsupported node-to-node protocol version " ++ show x
230231
x -> fail $ "FromJSON.NodeToNodeVersion: error parsing NodeToNodeVersion: " ++ show x
231232

232233
instance ToJSON NodeToNodeVersion where
233234
toJSON NodeToNodeV_14 = Number 14
235+
toJSON NodeToNodeV_15 = Number 15
234236

235237
instance FromJSON NodeToClientVersion where
236238
parseJSON = \case

0 commit comments

Comments
 (0)