@@ -221,6 +221,13 @@ func (c *Connection) shutdown() {
221221// setupConnection establishes the muxer, configures and starts the handshake process, and initializes
222222// the appropriate mini-protocols
223223func (c * Connection ) setupConnection () error {
224+ // Check network magic value
225+ if c .networkMagic == 0 {
226+ return fmt .Errorf (
227+ "invalid network magic value provided: %d\n " ,
228+ c .networkMagic ,
229+ )
230+ }
224231 // Start Goroutine to shutdown when doneChan is closed
225232 go func () {
226233 <- c .doneChan
@@ -255,36 +262,41 @@ func (c *Connection) setupConnection() error {
255262 Muxer : c .muxer ,
256263 ErrorChan : c .protoErrorChan ,
257264 }
258- var protoVersions []uint16
259265 if c .useNodeToNodeProto {
260- protoVersions = GetProtocolVersionsNtN ()
261266 protoOptions .Mode = protocol .ProtocolModeNodeToNode
262267 } else {
263- protoVersions = GetProtocolVersionsNtC ()
264268 protoOptions .Mode = protocol .ProtocolModeNodeToClient
265269 }
266270 if c .server {
267271 protoOptions .Role = protocol .ProtocolRoleServer
268272 } else {
269273 protoOptions .Role = protocol .ProtocolRoleClient
270274 }
271- // Check network magic value
272- if c .networkMagic == 0 {
273- return fmt .Errorf (
274- "invalid network magic value provided: %d\n " ,
275- c .networkMagic ,
276- )
275+ // Generate protocol version map for handshake
276+ handshakeDiffusionMode := protocol .DiffusionModeInitiatorOnly
277+ if c .fullDuplex {
278+ handshakeDiffusionMode = protocol .DiffusionModeInitiatorAndResponder
277279 }
280+ protoVersions := protocol .GetProtocolVersionMap (
281+ protoOptions .Mode ,
282+ c .networkMagic ,
283+ handshakeDiffusionMode ,
284+ // TODO: make these configurable
285+ protocol .PeerSharingModeNoPeerSharing ,
286+ protocol .QueryModeDisabled ,
287+ )
278288 // Perform handshake
279289 var handshakeVersion uint16
280290 var handshakeFullDuplex bool
281291 handshakeConfig := handshake .NewConfig (
282- handshake .WithProtocolVersions (protoVersions ),
283- handshake .WithNetworkMagic (c .networkMagic ),
284- handshake .WithClientFullDuplex (c .fullDuplex ),
285- handshake .WithFinishedFunc (func (version uint16 , fullDuplex bool ) error {
292+ handshake .WithProtocolVersionMap (protoVersions ),
293+ handshake .WithFinishedFunc (func (version uint16 , versionData protocol.VersionData ) error {
286294 handshakeVersion = version
287- handshakeFullDuplex = fullDuplex
295+ if c .useNodeToNodeProto {
296+ if versionData .DiffusionMode () == protocol .DiffusionModeInitiatorAndResponder {
297+ handshakeFullDuplex = true
298+ }
299+ }
288300 close (c .handshakeFinishedChan )
289301 return nil
290302 }),
@@ -307,10 +319,6 @@ func (c *Connection) setupConnection() error {
307319 }
308320 // Provide the negotiated protocol version to the various mini-protocols
309321 protoOptions .Version = handshakeVersion
310- // Drop bit used to signify NtC protocol versions
311- if protoOptions .Version > protocolVersionNtCFlag {
312- protoOptions .Version = protoOptions .Version - protocolVersionNtCFlag
313- }
314322 // Start Goroutine to pass along errors from the mini-protocols
315323 c .waitGroup .Add (1 )
316324 go func () {
@@ -331,7 +339,7 @@ func (c *Connection) setupConnection() error {
331339 }()
332340 // Configure the relevant mini-protocols
333341 if c .useNodeToNodeProto {
334- versionNtN := GetProtocolVersionNtN (handshakeVersion )
342+ versionNtN := protocol . GetProtocolVersion (handshakeVersion )
335343 protoOptions .Mode = protocol .ProtocolModeNodeToNode
336344 c .chainSync = chainsync .New (protoOptions , c .chainSyncConfig )
337345 c .blockFetch = blockfetch .New (protoOptions , c .blockFetchConfig )
@@ -365,7 +373,7 @@ func (c *Connection) setupConnection() error {
365373 }
366374 }
367375 } else {
368- versionNtC := GetProtocolVersionNtC (handshakeVersion )
376+ versionNtC := protocol . GetProtocolVersion (handshakeVersion )
369377 protoOptions .Mode = protocol .ProtocolModeNodeToClient
370378 c .chainSync = chainsync .New (protoOptions , c .chainSyncConfig )
371379 c .localTxSubmission = localtxsubmission .New (protoOptions , c .localTxSubmissionConfig )
0 commit comments