@@ -78,7 +78,7 @@ public sealed partial class Node : Runnable
78
78
79
79
public readonly string Version ;
80
80
81
- public readonly int Port ;
81
+ public readonly int SyncPort ;
82
82
public readonly string Host ;
83
83
public readonly string PublicEndpoint ;
84
84
public readonly PeerCaps Capabilities ;
@@ -113,11 +113,13 @@ public sealed partial class Node : Runnable
113
113
114
114
private DateTime _lastRequestTime = DateTime . UtcNow ;
115
115
116
+ public readonly PeerPort [ ] AvailablePorts ;
117
+
116
118
public bool IsFullySynced { get ; private set ; }
117
119
118
120
public string ProxyURL = null ;
119
121
120
- public Node ( string version , Nexus nexus , Mempool mempool , PhantasmaKeys keys , string publicHost , int port , PeerCaps caps , IEnumerable < string > seeds , Logger log )
122
+ public Node ( string version , Nexus nexus , Mempool mempool , PhantasmaKeys keys , string publicHost , IEnumerable < PeerPort > availablePorts , PeerCaps caps , IEnumerable < string > seeds , Logger log )
121
123
{
122
124
if ( mempool != null )
123
125
{
@@ -129,11 +131,15 @@ public Node(string version, Nexus nexus, Mempool mempool, PhantasmaKeys keys, st
129
131
Throw . If ( caps . HasFlag ( PeerCaps . Mempool ) , "mempool included in caps but mempool instance is null" ) ;
130
132
}
131
133
134
+ var syncPort = availablePorts . FirstOrDefault ( x => x . Name . Equals ( "sync" , StringComparison . OrdinalIgnoreCase ) ) . Port ;
135
+ Throw . If ( syncPort <= 0 , "missing sync port" ) ;
136
+
132
137
this . Logger = Logger . Init ( log ) ;
133
138
134
139
this . Version = version ;
135
140
this . Nexus = nexus ;
136
- this . Port = port ;
141
+ this . SyncPort = syncPort ;
142
+ this . AvailablePorts = availablePorts . ToArray ( ) ;
137
143
this . Keys = keys ;
138
144
this . Capabilities = caps ;
139
145
@@ -157,7 +163,7 @@ public Node(string version, Nexus nexus, Mempool mempool, PhantasmaKeys keys, st
157
163
Throw . If ( publicHost . Contains ( ":" ) , "invalid host, protocol or port number should not be included" ) ;
158
164
this . Host = publicHost ;
159
165
160
- this . PublicEndpoint = $ "tcp:{ publicHost } :{ port } ";
166
+ this . PublicEndpoint = $ "tcp:{ publicHost } :{ syncPort } ";
161
167
162
168
if ( this . Capabilities . HasFlag ( PeerCaps . Sync ) )
163
169
{
@@ -166,7 +172,7 @@ public Node(string version, Nexus nexus, Mempool mempool, PhantasmaKeys keys, st
166
172
// TODO this is a security issue, later change this to be configurable and default to localhost
167
173
var bindAddress = IPAddress . Any ;
168
174
169
- listener = new TcpListener ( bindAddress , port ) ;
175
+ listener = new TcpListener ( bindAddress , syncPort ) ;
170
176
171
177
if ( seeds . Any ( ) )
172
178
{
@@ -220,7 +226,7 @@ public bool ParseEndpoint(string src, out PeerProtocol protocol, out IPAddress i
220
226
}
221
227
else
222
228
{
223
- port = this . Port ;
229
+ port = this . SyncPort ;
224
230
}
225
231
226
232
if ( ! IPAddress . TryParse ( src , out ipAddress ) )
@@ -326,7 +332,7 @@ protected override void OnStart()
326
332
{
327
333
if ( this . Capabilities . HasFlag ( PeerCaps . Sync ) )
328
334
{
329
- Logger . Message ( $ "Phantasma node listening on port { Port } , using address: { Address } ") ;
335
+ Logger . Message ( $ "Phantasma node listening on port { SyncPort } , using address: { Address } ") ;
330
336
331
337
listener . Start ( ) ;
332
338
}
@@ -465,7 +471,7 @@ private void HandleConnection(Socket socket)
465
471
var peer = new TCPPeer ( socket ) ;
466
472
467
473
// this initial message is not only used to fetch chains but also to verify identity of peers
468
- var requestKind = RequestKind . Chains | RequestKind . Peers ;
474
+ var requestKind = RequestKind . Chains | RequestKind . Peers | RequestKind . Info ;
469
475
if ( Capabilities . HasFlag ( PeerCaps . Mempool ) )
470
476
{
471
477
requestKind |= RequestKind . Mempool ;
@@ -688,6 +694,11 @@ private Message HandleMessage(Peer peer, Message msg)
688
694
answer . SetPeers ( this . Peers . Where ( x => x != peer ) . Select ( x => x . Endpoint . ToString ( ) ) ) ;
689
695
}
690
696
697
+ if ( request . Kind . HasFlag ( RequestKind . Info ) )
698
+ {
699
+ answer . SetInfo ( this . Version , this . Capabilities , this . MinimumFee , this . MinimumPoW , this . AvailablePorts ) ;
700
+ }
701
+
691
702
if ( request . Kind . HasFlag ( RequestKind . Chains ) )
692
703
{
693
704
var chainList = Nexus . GetChains ( Nexus . RootStorage ) ;
0 commit comments