22using NetworkLibrary . Components ;
33using NetworkLibrary . MessageProtocol ;
44using NetworkLibrary . MessageProtocol . Serialization ;
5+ using NetworkLibrary . UDP . Reliable ;
56using NetworkLibrary . Utils ;
67using Protobuff . P2P ;
78using System . Collections . Concurrent ;
89using System . Diagnostics ;
10+ using System . Linq ;
911using System . Runtime . CompilerServices ;
1012using System . Security . Cryptography . X509Certificates ;
1113
@@ -19,10 +21,68 @@ static void Main(string[] args)
1921 {
2022 //ThreadPool.SetMinThreads(2000, 2000);
2123 MiniLogger . AllLog += Console . WriteLine ;
22- RelayTest ( ) ;
24+ //PoolBench();
25+ RelayTest ( ) ;
26+ // TestReliableModules();
2327
2428 Console . ReadLine ( ) ;
2529 }
30+
31+ private static void TestReliableModules ( )
32+ {
33+ Console . Clear ( ) ;
34+ Console . ReadLine ( ) ;
35+ Stopwatch sw = new Stopwatch ( ) ;
36+ int count = 10000 ;
37+ int completed = count ;
38+ Mockup m = new Mockup ( ) ;
39+ m . RemoveNoiseFeedback = true ;
40+ m . RemoveNoiseSend = true ;
41+
42+ byte [ ] data = new byte [ 40 ] ;
43+ byte [ ] data1 = new byte [ 1 ] ;
44+ ArraySegment < byte > f = new ArraySegment < byte > ( data ) ;
45+ ArraySegment < byte > s = new ArraySegment < byte > ( data1 , 0 , data1 . Length - 0 ) ;
46+ byte [ ] d4 = new byte [ 129000 + 65555 ] ;
47+
48+ int ccc = f . Count + s . Count ;
49+
50+ m . OnReceived += ( voff , off , cnt ) =>
51+ {
52+ if ( cnt == ccc )
53+ {
54+
55+ if ( Interlocked . Decrement ( ref completed ) == 0 )
56+ {
57+
58+ Console . WriteLine ( "########################################" ) ;
59+ Console . WriteLine ( sw . ElapsedMilliseconds ) ;
60+
61+ }
62+ }
63+ else
64+ {
65+
66+ }
67+ } ;
68+ sw . Start ( ) ;
69+
70+ for ( int i = 0 ; i < count ; i ++ )
71+ {
72+ m . SendTest ( f , s ) ;
73+ //m.SendTest(d4,0,d4.Length);
74+
75+ }
76+ while ( true )
77+ {
78+ Console . ReadLine ( ) ;
79+ Console . WriteLine ( "completed: " + completed ) ;
80+ Console . WriteLine ( "arrived : " + m . getArrivedCount ( ) ) ;
81+ Console . WriteLine ( "pending : " + m . getActiveCount ( ) ) ;
82+ }
83+
84+ }
85+
2686 private static void SerializerTest ( )
2787 {
2888 PooledMemoryStream stream = new PooledMemoryStream ( ) ;
@@ -63,20 +123,21 @@ private static void SerializerTest()
63123 Header = "Test" ,
64124 Payload = new byte [ 32 ]
65125 } ;
126+ static Stopwatch sw = new Stopwatch ( ) ;
66127 private static async void RelayTest ( )
67128 {
68- string ip = "127.0.0.1" ;
129+ string ip = "79.19.128.177" ;
130+ //string ip = "127.0.0.1";
69131
70132
71133 var cert = new X509Certificate2 ( "client.pfx" , "greenpass" ) ;
72134 var scert = new X509Certificate2 ( "server.pfx" , "greenpass" ) ;
73135
74- var server = new SecureProtoRelayServer ( 20011 , scert ) ;
75-
76- // Task.Run(async () => { while (true) { await Task.Delay(10000); server.GetTcpStatistics(out var generalStats, out _); Console.WriteLine(generalStats.ToString()); } });
77- Thread . Sleep ( 1000 ) ;
136+ //var server = new SecureProtoRelayServer(20011, scert);
137+ // server.StartServer();
138+ //Task.Run(async () => { while (true) { await Task.Delay(10000); server.GetTcpStatistics(out var generalStats, out _); Console.WriteLine(generalStats.ToString()); } });
78139 var clients = new ConcurrentBag < RelayClient > ( ) ;
79- int numclients = 20 ;
140+ int numclients = 2 ;
80141 var pending = new Task [ numclients ] ;
81142 Parallel . For ( 0 , numclients , ( i ) =>
82143 //for (int i = 0; i < numclients; i++)
@@ -85,13 +146,13 @@ private static async void RelayTest()
85146 var client = new RelayClient ( cert ) ;
86147 client . OnMessageReceived += ( reply ) => ClientMsgReceived ( client , reply ) ;
87148 client . OnUdpMessageReceived += ( reply ) => ClientUdpReceived ( client , reply ) ;
88- //client.OnPeerRegistered+= (id)=> client.RequestHolePunchAsync(id, 10000, false);
149+ //client.OnPeerRegistered += (id) => { if ( client.sessionId.CompareTo(id) > 0) client. RequestHolePunchAsync(id, 10000, false); } ;
89150 try
90151 {
91152 pending [ i ] = client . ConnectAsync ( ip , 20011 ) ;
92153 // client.Connect(ip, 20011);
93154 clients . Add ( client ) ;
94- client . StartPingService ( ) ;
155+ // client.StartPingService();
95156 }
96157 catch { }
97158
@@ -100,7 +161,7 @@ private static async void RelayTest()
100161 ) ;
101162 Task . WaitAll ( pending ) ;
102163 Console . WriteLine ( "All Connected" ) ;
103- Thread . Sleep ( 5000 ) ;
164+ Thread . Sleep ( 2000 ) ;
104165 int cc = 0 ;
105166 List < Task < bool > > pndg = new List < Task < bool > > ( ) ;
106167 foreach ( var client in clients )
@@ -115,8 +176,8 @@ private static async void RelayTest()
115176 if ( peer . Key == Guid . Empty )
116177 throw new Exception ( ) ;
117178
118- var a = client . RequestHolePunchAsync ( peer . Key , 10000 , false ) ;
119- pndg . Add ( a ) ;
179+ // var a = client.RequestHolePunchAsync(peer.Key, 10000, false);
180+ // pndg.Add(a);
120181 //client.TestHP(peer.Key, 10000, false);
121182 // Console.WriteLine(peer.Key+" cnt=> "+ ++cc);
122183 }
@@ -125,70 +186,83 @@ private static async void RelayTest()
125186 }
126187 Task . WaitAll ( pndg . ToArray ( ) ) ;
127188 Console . WriteLine ( "all good" ) ;
128- int kk = 0 ;
129- foreach ( var item in pndg )
130- {
131- kk ++ ;
132-
133- if ( item . Result == false )
134- {
135- Console . WriteLine ( " +++++++++-------***************---------------- Fucked" ) ;
136- }
137- else
138- {
139- Console . WriteLine ( "All good" + kk ) ;
140- }
141- }
142-
143- Task . Run ( async ( ) =>
144- {
145- return ;
146- while ( true )
147- {
148- await Task . Delay ( 3000 ) ;
149- Console . WriteLine ( totMsgCl ) ;
150- }
151-
152- } ) ;
153- Thread . Sleep ( 5000 ) ;
154- Parallel . ForEach ( clients , ( client ) =>
189+
190+
191+ Thread . Sleep ( 100 ) ;
192+ // Parallel.ForEach(clients, (client) =>
193+ foreach ( var client in clients )
155194 {
156195 var testMessage = new MessageEnvelope ( )
157196 {
158197 Header = "Test" ,
159- // Payload = new byte[32 ]
198+ Payload = new byte [ 320000000 ]
160199 } ;
161200 for ( int i = 0 ; i < 1 ; i ++ )
162201 {
163202 //return;
164203 foreach ( var peer in client . Peers . Keys )
165204 {
166205 //await client.SendRequestAndWaitResponse(peer, testMessage,1000);
167- //client.SendAsyncMessage(peer, testMessage);
206+ //client.SendAsyncMessage(peer, testMessage);
168207
169- client . SendUdpMesssage ( peer , testMessage ) ;
208+ //client.SendUdpMesssage(peer, testMessage);
209+ // client.BroadcastMessage(testMessage);
210+ //client.BroadcastUdpMessage(testMessage);
211+ client . SendRudpMessage ( peer , testMessage ) ;
170212 }
171213 }
214+ testMessage = new MessageEnvelope ( )
215+ {
216+ Header = "Test" ,
217+ Payload = new byte [ 320 ]
218+ } ;
219+ //for (int i = 0; i < 20; i++)
220+ //{
221+ // foreach (var peer in client.Peers.Keys)
222+ // client.SendRudpMessage(peer, testMessage);
172223
173- } ) ;
224+ //}
225+ break ;
174226
175-
227+ }
228+ // );
229+
230+ sw . Start ( ) ;
176231
177232 void ClientMsgReceived ( RelayClient client , MessageEnvelope reply )
178233 {
179234 //Interlocked.Increment(ref totMsgCl);
180235 client . SendAsyncMessage ( reply . From , reply ) ;
181-
236+ // Console.WriteLine("R " + sw.ElapsedMilliseconds);
237+ sw . Restart ( ) ;
182238 }
183239
184-
240+
185241 void ClientUdpReceived ( RelayClient client , MessageEnvelope reply )
186242 {
187- // Interlocked.Increment(ref totMsgCl);
188- client . SendUdpMesssage ( reply . From , reply ) ;
189243
244+ // Interlocked.Increment(ref totMsgCl);
245+ //client.SendUdpMesssage(reply.From, reply);
246+ client . SendRudpMessage ( reply . From , reply ) ;
247+
248+
249+ // Console.WriteLine(" ************ R "+sw.ElapsedMilliseconds);
250+ sw . Restart ( ) ;
251+
252+
253+ //if(Interlocked.Increment(ref am) % 10000 == 0)
254+ // {
255+ // Console.WriteLine("time " + sw.ElapsedMilliseconds);
256+ // sw.Restart();
257+
258+ // }
259+
260+ //sw.Restart();
261+ //Console.WriteLine("R");
262+
190263 }
264+ Console . ReadLine ( ) ;
191265 }
192-
266+ static long am = 0 ;
193267 }
194268}
0 commit comments