MCPcopy Create free account
hub / github.com/ethstorage/es-node / createLocalHostAndSyncClient

Function createLocalHostAndSyncClient

ethstorage/p2p/protocol/sync_test.go:332–371  ·  view source on GitHub ↗
(t *testing.T, chainID *big.Int, db ethdb.Database,
	storageManager StorageManager, metrics SyncClientMetrics, mux *event.Feed)

Source from the content-addressed store, hash-verified

330}
331
332func 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, &params, 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
373func createRemoteHost(t *testing.T, ctx context.Context, chainID *big.Int,
374 storageManager *mockStorageManagerReader, db ethdb.Database, metrics SyncServerMetrics) host.Host {

Callers 8

TestSync_RequestL2RangeFunction · 0.85
TestSync_RequestL2ListFunction · 0.85
testSyncFunction · 0.85
TestAddPeerDuringSyncingFunction · 0.85
TestAddPeerAfterSyncDoneFunction · 0.85
TestFillEmptyFunction · 0.85

Calls 8

AddPeerMethod · 0.95
RemovePeerMethod · 0.95
getNetHostFunction · 0.85
NewSyncClientFunction · 0.85
ConvertToShardListFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected