Skip to content

Commit b4eb8a2

Browse files
Theodor Rauchjkralik
authored andcommitted
fix: only one request per endpoint (peer)
1 parent 8a3f4a0 commit b4eb8a2

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

net/blockwise/blockwise.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (b *BlockWise[C]) Handle(w *responsewriter.ResponseWriter[C], r *pool.Messa
361361
exchangeKey = r.Token().Hash()
362362
} else {
363363
var err error
364-
exchangeKey, err = getExchangeKey(remoteAddr, r)
364+
exchangeKey, err = getExchangeKey(remoteAddr)
365365
if err != nil {
366366
b.errors(fmt.Errorf("cannot get exchange key from request Parameters(%v): %w", r, err))
367367
return
@@ -865,28 +865,15 @@ func (b *BlockWise[C]) processReceivedMessage(w *responsewriter.ResponseWriter[C
865865
}
866866

867867
// getExchangeKey returns a key for the blockwise exchange cache.
868-
// According to RFC 7252 the token is to be treated as opaque if not created by the entity and
869-
// according to RFC 7959 there can't be concurrent blockwise transfers for the same endpoint and resource
870-
// so we can use the address of the endpoint and the path of the resource as hash as a key.
871-
func getExchangeKey(addr net.Addr, r *pool.Message) (uint64, error) {
872-
//TODO: Possibly seperate hash domains of token hashes and hashes from path, and address, to avoid systematic overlaps.
868+
// According to RFC 7252: "[...] An empty token value is appropriate e.g., when no other tokens are in use to a destination"
869+
// so we need to generate a key from the remote address of the corresponding endpoint.
870+
func getExchangeKey(addr net.Addr) (uint64, error) {
873871

874872
if addr == nil {
875873
return 0, errors.New("cannot get exchange key: addr is nil")
876874
}
877-
if r == nil {
878-
return 0, errors.New("cannot get exchange key: request is nil")
879-
}
880-
path, err := r.Path()
881-
if err != nil {
882-
return 0, fmt.Errorf("cannot get path from request(%v): %w", r, err)
883-
}
884-
code := r.Code()
885875

886876
h := fnv.New64a()
887-
h.Write([]byte{byte(code >> 8), byte(code), '|'})
888-
h.Write([]byte(path))
889-
h.Write([]byte{'|'})
890877
h.Write([]byte(addr.String()))
891878
return h.Sum64(), nil
892879
}

0 commit comments

Comments
 (0)