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....
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)
Addr storage.Address
SData []byte // the stored chunk Data (incl size)
peer *Peer // set in handleChunkDeliveryMsg
}
//...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
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
if syncing {
msg = &ChunkDeliveryMsgSyncing{
Addr: chunk.Address(),
SData: chunk.Data(),
Syncing: syncing,
Addr: chunk.Address(),
SData: chunk.Data(),
}
spanName += ".syncing"
} else {
msg = &ChunkDeliveryMsgRetrieval{
Addr: chunk.Address(),
SData: chunk.Data(),
Syncing: syncing,
Addr: chunk.Address(),
SData: chunk.Data(),
}
spanName += ".retrieval"
}
ctx, sp = spancontext.StartSpan(
ctx,
spanName)
defer sp.Finish()
return p.SendPriority(ctx, msg, priority)
}