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

@ -195,7 +195,6 @@ type ChunkDeliveryMsg struct {
Addr storage.Address
SData []byte // the stored chunk Data (incl size)
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

View file

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