Commit e3dc1591 authored by Zahoor Mohamed's avatar Zahoor Mohamed Committed by GitHub

Fix panic in tags debug api (#493)

fix panics in /files and /bytes. Also fix the increment of state sent and statesynced counters.
parent e4686725
...@@ -27,6 +27,9 @@ type bytesPostResponse struct { ...@@ -27,6 +27,9 @@ type bytesPostResponse struct {
// bytesUploadHandler handles upload of raw binary data of arbitrary length. // bytesUploadHandler handles upload of raw binary data of arbitrary length.
func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
ta := s.createTag(w, r) ta := s.createTag(w, r)
if ta == nil {
return
}
// Add the tag to the context // Add the tag to the context
r = r.WithContext(context.WithValue(r.Context(), tags.TagsContextKey{}, ta)) r = r.WithContext(context.WithValue(r.Context(), tags.TagsContextKey{}, ta))
......
...@@ -67,6 +67,9 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -67,6 +67,9 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) {
var fileSize uint64 var fileSize uint64
ta := s.createTag(w, r) ta := s.createTag(w, r)
if ta == nil {
return
}
// Add the tag to the context // Add the tag to the context
r = r.WithContext(context.WithValue(r.Context(), tags.TagsContextKey{}, ta)) r = r.WithContext(context.WithValue(r.Context(), tags.TagsContextKey{}, ta))
......
...@@ -176,7 +176,14 @@ func (s *SimpleSplitterJob) sumLevel(lvl int) ([]byte, error) { ...@@ -176,7 +176,14 @@ func (s *SimpleSplitterJob) sumLevel(lvl int) ([]byte, error) {
ref := s.hasher.Sum(nil) ref := s.hasher.Sum(nil)
addr = swarm.NewAddress(ref) addr = swarm.NewAddress(ref)
ch := swarm.NewChunk(addr, c) // Add tag to the chunk if tag is valid
var ch swarm.Chunk
if s.tagg != nil {
ch = swarm.NewChunk(addr, c).WithTagID(s.tagg.Uid)
} else {
ch = swarm.NewChunk(addr, c)
}
seen, err := s.putter.Put(s.ctx, storage.ModePutUpload, ch) seen, err := s.putter.Put(s.ctx, storage.ModePutUpload, ch)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -347,6 +347,7 @@ func NewBee(o Options) (*Bee, error) { ...@@ -347,6 +347,7 @@ func NewBee(o Options) (*Bee, error) {
Tracer: tracer, Tracer: tracer,
TopologyDriver: topologyDriver, TopologyDriver: topologyDriver,
Storer: storer, Storer: storer,
Tags: tagg,
}) })
// register metrics from components // register metrics from components
debugAPIService.MustRegisterMetrics(p2ps.Metrics()...) debugAPIService.MustRegisterMetrics(p2ps.Metrics()...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment