|
@@ -31,6 +31,7 @@ import (
|
|
|
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
|
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
|
|
"github.com/ethereum/go-ethereum/swarm/state"
|
|
"github.com/ethereum/go-ethereum/swarm/state"
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
|
|
|
|
+ "github.com/ethereum/go-ethereum/swarm/tracing"
|
|
|
opentracing "github.com/opentracing/opentracing-go"
|
|
opentracing "github.com/opentracing/opentracing-go"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -65,7 +66,6 @@ type Peer struct {
|
|
|
// on creating a new client in offered hashes handler.
|
|
// on creating a new client in offered hashes handler.
|
|
|
clientParams map[Stream]*clientParams
|
|
clientParams map[Stream]*clientParams
|
|
|
quit chan struct{}
|
|
quit chan struct{}
|
|
|
- spans sync.Map
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type WrappedPriorityMsg struct {
|
|
type WrappedPriorityMsg struct {
|
|
@@ -83,16 +83,10 @@ func NewPeer(peer *protocols.Peer, streamer *Registry) *Peer {
|
|
|
clients: make(map[Stream]*client),
|
|
clients: make(map[Stream]*client),
|
|
|
clientParams: make(map[Stream]*clientParams),
|
|
clientParams: make(map[Stream]*clientParams),
|
|
|
quit: make(chan struct{}),
|
|
quit: make(chan struct{}),
|
|
|
- spans: sync.Map{},
|
|
|
|
|
}
|
|
}
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
go p.pq.Run(ctx, func(i interface{}) {
|
|
go p.pq.Run(ctx, func(i interface{}) {
|
|
|
wmsg := i.(WrappedPriorityMsg)
|
|
wmsg := i.(WrappedPriorityMsg)
|
|
|
- defer p.spans.Delete(wmsg.Context)
|
|
|
|
|
- sp, ok := p.spans.Load(wmsg.Context)
|
|
|
|
|
- if ok {
|
|
|
|
|
- defer sp.(opentracing.Span).Finish()
|
|
|
|
|
- }
|
|
|
|
|
err := p.Send(wmsg.Context, wmsg.Msg)
|
|
err := p.Send(wmsg.Context, wmsg.Msg)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Error("Message send error, dropping peer", "peer", p.ID(), "err", err)
|
|
log.Error("Message send error, dropping peer", "peer", p.ID(), "err", err)
|
|
@@ -129,6 +123,7 @@ func NewPeer(peer *protocols.Peer, streamer *Registry) *Peer {
|
|
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
|
<-p.quit
|
|
<-p.quit
|
|
|
|
|
+
|
|
|
cancel()
|
|
cancel()
|
|
|
}()
|
|
}()
|
|
|
return p
|
|
return p
|
|
@@ -158,21 +153,15 @@ func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8,
|
|
|
spanName += ".retrieval"
|
|
spanName += ".retrieval"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return p.SendPriority(ctx, msg, priority, spanName)
|
|
|
|
|
|
|
+ ctx = context.WithValue(ctx, "stream_send_tag", nil)
|
|
|
|
|
+ return p.SendPriority(ctx, msg, priority)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SendPriority sends message to the peer using the outgoing priority queue
|
|
// SendPriority sends message to the peer using the outgoing priority queue
|
|
|
-func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8, traceId string) error {
|
|
|
|
|
|
|
+func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8) error {
|
|
|
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("peer.sendpriority_t.%d", priority), nil).UpdateSince(time.Now())
|
|
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("peer.sendpriority_t.%d", priority), nil).UpdateSince(time.Now())
|
|
|
|
|
+ tracing.StartSaveSpan(ctx)
|
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("peer.sendpriority.%d", priority), nil).Inc(1)
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("peer.sendpriority.%d", priority), nil).Inc(1)
|
|
|
- if traceId != "" {
|
|
|
|
|
- var sp opentracing.Span
|
|
|
|
|
- ctx, sp = spancontext.StartSpan(
|
|
|
|
|
- ctx,
|
|
|
|
|
- traceId,
|
|
|
|
|
- )
|
|
|
|
|
- p.spans.Store(ctx, sp)
|
|
|
|
|
- }
|
|
|
|
|
wmsg := WrappedPriorityMsg{
|
|
wmsg := WrappedPriorityMsg{
|
|
|
Context: ctx,
|
|
Context: ctx,
|
|
|
Msg: msg,
|
|
Msg: msg,
|
|
@@ -190,7 +179,8 @@ func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
|
|
|
var sp opentracing.Span
|
|
var sp opentracing.Span
|
|
|
ctx, sp := spancontext.StartSpan(
|
|
ctx, sp := spancontext.StartSpan(
|
|
|
context.TODO(),
|
|
context.TODO(),
|
|
|
- "send.offered.hashes")
|
|
|
|
|
|
|
+ "send.offered.hashes",
|
|
|
|
|
+ )
|
|
|
defer sp.Finish()
|
|
defer sp.Finish()
|
|
|
|
|
|
|
|
hashes, from, to, proof, err := s.setNextBatch(f, t)
|
|
hashes, from, to, proof, err := s.setNextBatch(f, t)
|
|
@@ -215,7 +205,8 @@ func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
|
|
|
Stream: s.stream,
|
|
Stream: s.stream,
|
|
|
}
|
|
}
|
|
|
log.Trace("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "len", len(hashes), "from", from, "to", to)
|
|
log.Trace("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "len", len(hashes), "from", from, "to", to)
|
|
|
- return p.SendPriority(ctx, msg, s.priority, "send.offered.hashes")
|
|
|
|
|
|
|
+ ctx = context.WithValue(ctx, "stream_send_tag", "send.offered.hashes")
|
|
|
|
|
+ return p.SendPriority(ctx, msg, s.priority)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (p *Peer) getServer(s Stream) (*server, error) {
|
|
func (p *Peer) getServer(s Stream) (*server, error) {
|