Skip to content

Commit 3aa3bee

Browse files
authored
Move long messagequeue comment to doc.go (#814)
1 parent 699c35b commit 3aa3bee

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Package messagequeue implements a queue of want messages to send to peers.
2+
//
3+
// There is a MessageQueue for each peer. The MessageQueue does not enqueue
4+
// individual outgoing messages, but accumulates information to put into the
5+
// next message. Each MessageQueue keeps want lists and CIDs to cancel:
6+
//
7+
// - sent/pending peer wants + sent times
8+
// - sent/pending broadcast wants + sent times
9+
// - cancel CIDs
10+
//
11+
// As messages are added, existing wantlist items may be changed or removed.
12+
// For example, adding a cancel to the queue for some CIDs also removes any
13+
// pending wants for those same CIDs. Adding a want will remove a cancel for
14+
// that CID. If a want already exists then only the type and priority may be
15+
// adjusted for that same want, so that duplicate messages are not sent.
16+
//
17+
// When enough message updates have accumulated or it has been long enough
18+
// since the previous message was sent, then send the current message. The
19+
// message contains wants and cancels up to a limited size, and is sent to the
20+
// peer. The time that the message was sent is recorded.
21+
//
22+
// If a want has been sent with no response received, for longer than the
23+
// rebroadcast interval, then the want is moved back to the pending list to be
24+
// resent to the peer.
25+
//
26+
// When a response is received, the earliest request time is used to calculate
27+
// the longest latency for updating the message timeout time. The sent times
28+
// are cleared for CIDs in the response.
29+
package messagequeue

bitswap/client/internal/messagequeue/messagequeue.go

-21
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,6 @@ type MessageNetwork interface {
6161
}
6262

6363
// MessageQueue implements queue of want messages to send to peers.
64-
//
65-
// There is a MessageQueue for each peer. Each MessageQueue keeps want lists
66-
// and CIDs to cancel:
67-
//
68-
// - sent/pending peer wants + sent times
69-
// - sent/pending broadcast wants + sent times
70-
// - cancel CIDs
71-
//
72-
// As different messages are added, existing messages already present may be
73-
// changed or removed. For example, adding a cancel to the queue for some CIDs
74-
// will also remove any pending wants for those same CIDs. Adding a want will
75-
// remove a cancel for that CID. If a want already exists then only the type
76-
// and priority may be adjusted for that same want, so that duplicate messages
77-
// are not sent.
78-
//
79-
// Periodically, on a schedule determined by the peer's response latency, the
80-
// current set of messages (wants and cancels) is sent to the peer. The time
81-
// that wants are sent is recorded. When a response to a want message is
82-
// received, the elapsed time since the request was sent is recorded in the
83-
// message queue. If there are a sufficient number of updates to send, a
84-
// bitswap message is sent immediately.
8564
type MessageQueue struct {
8665
ctx context.Context
8766
shutdown func()

0 commit comments

Comments
 (0)