Skip to content

Commit 430a35a

Browse files
committed
fix: stamped putter support for streamed chunk endpoint
1 parent bf26745 commit 430a35a

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

pkg/api/chunk_stream.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (s *Service) chunkUploadStreamHandler(w http.ResponseWriter, r *http.Reques
2929

3030
headers := struct {
3131
BatchID []byte `map:"Swarm-Postage-Batch-Id" validate:"required"`
32+
StampSig []byte `map:"Swarm-Postage-Stamp"`
3233
SwarmTag uint64 `map:"Swarm-Tag"`
3334
}{}
3435
if response := s.mapStructure(r.Header, &headers); response != nil {
@@ -57,11 +58,30 @@ func (s *Service) chunkUploadStreamHandler(w http.ResponseWriter, r *http.Reques
5758

5859
// if tag not specified use direct upload
5960
// Using context.Background here because the putter's lifetime extends beyond that of the HTTP request.
60-
putter, err := s.newStamperPutter(context.Background(), putterOptions{
61-
BatchID: headers.BatchID,
62-
TagID: tag,
63-
Deferred: tag != 0,
64-
})
61+
var putter storer.PutterSession
62+
if len(headers.StampSig) != 0 {
63+
stamp := postage.Stamp{}
64+
if err := stamp.UnmarshalBinary(headers.StampSig); err != nil {
65+
errorMsg := "Stamp deserialization failure"
66+
logger.Debug(errorMsg, "error", err)
67+
logger.Error(nil, errorMsg)
68+
jsonhttp.BadRequest(w, errorMsg)
69+
return
70+
}
71+
72+
putter, err = s.newStampedPutter(context.Background(), putterOptions{
73+
BatchID: stamp.BatchID(),
74+
TagID: tag,
75+
Deferred: tag != 0,
76+
}, &stamp)
77+
} else {
78+
putter, err = s.newStamperPutter(context.Background(), putterOptions{
79+
BatchID: headers.BatchID,
80+
TagID: tag,
81+
Deferred: tag != 0,
82+
})
83+
}
84+
6585
if err != nil {
6686
logger.Debug("get putter failed", "error", err)
6787
logger.Error(nil, "get putter failed")

0 commit comments

Comments
 (0)