| 338 | }; |
| 339 | |
| 340 | struct P2PNetworkTest { |
| 341 | // Addresses to listen on |
| 342 | std::vector<Reference<IListener>> listeners; |
| 343 | // Addresses to randomly connect to |
| 344 | std::vector<NetworkAddress> remotes; |
| 345 | // Number of outgoing connections to maintain |
| 346 | int connectionsOut; |
| 347 | // Message size range to send on outgoing established connections |
| 348 | RandomIntRange requestBytes; |
| 349 | // Message size to reply with on incoming established connections |
| 350 | RandomIntRange replyBytes; |
| 351 | // Number of requests/replies per session |
| 352 | RandomIntRange requests; |
| 353 | // Delay after message send and receive are complete before closing connection |
| 354 | RandomIntRange idleMilliseconds; |
| 355 | // Random delay before socket reads |
| 356 | RandomIntRange waitReadMilliseconds; |
| 357 | // Random delay before socket writes |
| 358 | RandomIntRange waitWriteMilliseconds; |
| 359 | |
| 360 | double startTime; |
| 361 | int64_t bytesSent; |
| 362 | int64_t bytesReceived; |
| 363 | int sessionsIn; |
| 364 | int sessionsOut; |
| 365 | int connectErrors; |
| 366 | int acceptErrors; |
| 367 | int sessionErrors; |
| 368 | |
| 369 | Standalone<StringRef> msgBuffer; |
| 370 | |
| 371 | std::string statsString() { |
| 372 | double elapsed = now() - startTime; |
| 373 | std::string s = format( |
| 374 | "%.2f MB/s bytes in %.2f MB/s bytes out %.2f/s completed sessions in %.2f/s completed sessions out ", |
| 375 | bytesReceived / elapsed / 1e6, |
| 376 | bytesSent / elapsed / 1e6, |
| 377 | sessionsIn / elapsed, |
| 378 | sessionsOut / elapsed); |
| 379 | s += format("Total Errors %d connect=%d accept=%d session=%d", |
| 380 | connectErrors + acceptErrors + sessionErrors, |
| 381 | connectErrors, |
| 382 | acceptErrors, |
| 383 | sessionErrors); |
| 384 | bytesSent = 0; |
| 385 | bytesReceived = 0; |
| 386 | sessionsIn = 0; |
| 387 | sessionsOut = 0; |
| 388 | startTime = now(); |
| 389 | return s; |
| 390 | } |
| 391 | |
| 392 | P2PNetworkTest() {} |
| 393 | |
| 394 | P2PNetworkTest(std::string listenerAddresses, |
| 395 | std::string remoteAddresses, |
| 396 | int connectionsOut, |
| 397 | RandomIntRange sendMsgBytes, |
no test coverage detected