Request returns the bytes for the specified block after fetching them from the connected peer.
(ctx context.Context, req *Request)
| 346 | |
| 347 | // Request returns the bytes for the specified block after fetching them from the connected peer. |
| 348 | func (c *rawConnection) Request(ctx context.Context, req *Request) ([]byte, error) { |
| 349 | select { |
| 350 | case <-c.closed: |
| 351 | return nil, ErrClosed |
| 352 | case <-ctx.Done(): |
| 353 | return nil, ctx.Err() |
| 354 | default: |
| 355 | } |
| 356 | |
| 357 | rc := make(chan asyncResult, 1) |
| 358 | |
| 359 | c.awaitingMut.Lock() |
| 360 | id := c.nextID |
| 361 | c.nextID++ |
| 362 | if _, ok := c.awaiting[id]; ok { |
| 363 | c.awaitingMut.Unlock() |
| 364 | panic("id taken") |
| 365 | } |
| 366 | c.awaiting[id] = rc |
| 367 | c.awaitingMut.Unlock() |
| 368 | |
| 369 | req.ID = id |
| 370 | ok := c.send(ctx, req.toWire(), nil) |
| 371 | if !ok { |
| 372 | return nil, ErrClosed |
| 373 | } |
| 374 | |
| 375 | select { |
| 376 | case res, ok := <-rc: |
| 377 | if !ok { |
| 378 | return nil, ErrClosed |
| 379 | } |
| 380 | return res.val, res.err |
| 381 | case <-ctx.Done(): |
| 382 | return nil, ctx.Err() |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // ClusterConfig sends the cluster configuration message to the peer. |
| 387 | func (c *rawConnection) ClusterConfig(config *ClusterConfig, _ map[string]string) { |