(t *testing.T, chainID *big.Int, db ethdb.Database, storageManager StorageManager, metrics SyncClientMetrics, mux *event.Feed)
| 330 | } |
| 331 | |
| 332 | func createLocalHostAndSyncClient(t *testing.T, chainID *big.Int, db ethdb.Database, |
| 333 | storageManager StorageManager, metrics SyncClientMetrics, mux *event.Feed) (host.Host, *SyncClient) { |
| 334 | localHost := getNetHost(t) |
| 335 | |
| 336 | syncCl := NewSyncClient(lg, chainID, localHost.NewStream, storageManager, ¶ms, db, metrics, mux) |
| 337 | localHost.Network().Notify(&network.NotifyBundle{ |
| 338 | ConnectedF: func(nw network.Network, conn network.Conn) { |
| 339 | shards := make(map[common.Address][]uint64) |
| 340 | css, err := localHost.Peerstore().Get(conn.RemotePeer(), EthStorageENRKey) |
| 341 | if err != nil { |
| 342 | lg.Warn("Get shards from peer failed", "error", err.Error()) |
| 343 | } else { |
| 344 | shards = ConvertToShardList(css.([]*ContractShards)) |
| 345 | } |
| 346 | |
| 347 | added := syncCl.AddPeer(conn.RemotePeer(), shards, conn.Stat().Direction) |
| 348 | if !added { |
| 349 | conn.Close() |
| 350 | } |
| 351 | }, |
| 352 | DisconnectedF: func(nw network.Network, conn network.Conn) { |
| 353 | syncCl.RemovePeer(conn.RemotePeer()) |
| 354 | }, |
| 355 | }) |
| 356 | // the host may already be connected to peers, add them all to the sync client |
| 357 | for _, conn := range localHost.Network().Conns() { |
| 358 | shards := make(map[common.Address][]uint64) |
| 359 | css, err := localHost.Peerstore().Get(conn.RemotePeer(), EthStorageENRKey) |
| 360 | if err != nil { |
| 361 | lg.Warn("Get shards from peer failed", "error", err.Error()) |
| 362 | } else { |
| 363 | shards = ConvertToShardList(css.([]*ContractShards)) |
| 364 | } |
| 365 | added := syncCl.AddPeer(conn.RemotePeer(), shards, conn.Stat().Direction) |
| 366 | if !added { |
| 367 | conn.Close() |
| 368 | } |
| 369 | } |
| 370 | return localHost, syncCl |
| 371 | } |
| 372 | |
| 373 | func createRemoteHost(t *testing.T, ctx context.Context, chainID *big.Int, |
| 374 | storageManager *mockStorageManagerReader, db ethdb.Database, metrics SyncServerMetrics) host.Host { |
no test coverage detected