swarm/network/stream: addressed PR comments

This commit is contained in:
Fabio Barone 2018-10-16 13:03:26 -05:00
parent 492095764a
commit ae36406238
2 changed files with 16 additions and 15 deletions

View file

@ -192,10 +192,9 @@ func (d *Delivery) handleRetrieveRequestMsg(ctx context.Context, sp *Peer, req *
//Chunk delivery always uses the same message type.... //Chunk delivery always uses the same message type....
type ChunkDeliveryMsg struct { type ChunkDeliveryMsg struct {
Addr storage.Address Addr storage.Address
SData []byte // the stored chunk Data (incl size) SData []byte // the stored chunk Data (incl size)
peer *Peer // set in handleChunkDeliveryMsg peer *Peer // set in handleChunkDeliveryMsg
Syncing bool // if true, this is a delivery for syncing (no SWAP accounting needed)
} }
//...but swap accounting needs to disambiguate if it is a delivery for syncing or for retrieval //...but swap accounting needs to disambiguate if it is a delivery for syncing or for retrieval

View file

@ -131,29 +131,31 @@ func NewPeer(peer *protocols.Peer, streamer *Registry) *Peer {
// Depending on the `syncing` parameter we send different message types // Depending on the `syncing` parameter we send different message types
func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8, syncing bool) error { func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8, syncing bool) error {
var sp opentracing.Span var sp opentracing.Span
ctx, sp = spancontext.StartSpan(
ctx,
"send.chunk.delivery")
defer sp.Finish()
var msg interface{} var msg interface{}
spanName := "send.chunk.delivery"
//we send different types of messages if delivery is for syncing or retrievals, //we send different types of messages if delivery is for syncing or retrievals,
//even if handling and content of the message are the same, //even if handling and content of the message are the same,
//because swap accounting decides which messages need accounting based on the message type //because swap accounting decides which messages need accounting based on the message type
if syncing { if syncing {
msg = &ChunkDeliveryMsgSyncing{ msg = &ChunkDeliveryMsgSyncing{
Addr: chunk.Address(), Addr: chunk.Address(),
SData: chunk.Data(), SData: chunk.Data(),
Syncing: syncing,
} }
spanName += ".syncing"
} else { } else {
msg = &ChunkDeliveryMsgRetrieval{ msg = &ChunkDeliveryMsgRetrieval{
Addr: chunk.Address(), Addr: chunk.Address(),
SData: chunk.Data(), SData: chunk.Data(),
Syncing: syncing,
} }
spanName += ".retrieval"
} }
ctx, sp = spancontext.StartSpan(
ctx,
spanName)
defer sp.Finish()
return p.SendPriority(ctx, msg, priority) return p.SendPriority(ctx, msg, priority)
} }