makeHeaderFetcher retrieves a block header fetcher associated with a simulated peer.
(peer string, blocks map[common.Hash]*types.Block, drift time.Duration)
| 146 | |
| 147 | // makeHeaderFetcher retrieves a block header fetcher associated with a simulated peer. |
| 148 | func (f *fetcherTester) makeHeaderFetcher(peer string, blocks map[common.Hash]*types.Block, drift time.Duration) headerRequesterFn { |
| 149 | closure := make(map[common.Hash]*types.Block) |
| 150 | for hash, block := range blocks { |
| 151 | closure[hash] = block |
| 152 | } |
| 153 | // Create a function that return a header from the closure |
| 154 | return func(hash common.Hash) error { |
| 155 | // Gather the blocks to return |
| 156 | headers := make([]*types.Header, 0, 1) |
| 157 | if block, ok := closure[hash]; ok { |
| 158 | headers = append(headers, block.Header()) |
| 159 | } |
| 160 | // Return on a new thread |
| 161 | go f.fetcher.FilterHeaders(peer, headers, time.Now().Add(drift)) |
| 162 | |
| 163 | return nil |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // makeBodyFetcher retrieves a block body fetcher associated with a simulated peer. |
| 168 | func (f *fetcherTester) makeBodyFetcher(peer string, blocks map[common.Hash]*types.Block, drift time.Duration) bodyRequesterFn { |
no test coverage detected