Documentation
¶
Overview ¶
Package flowtable manages datagram flow registration, acceptance and expiry.
Index ¶
- func WriteAddrPort(h *maphash.Hash, ap netip.AddrPort)
- type Membership
- type Result
- type Table
- func (t *Table[K, P, S]) Accept() (S, error)
- func (t *Table[K, P, S]) Add(k K, s S, backlog bool) (S, Result)
- func (t *Table[K, P, S]) AddOrBind(k K, s S, prepare func(S)) (S, Result)
- func (t *Table[K, P, S]) AddUnbound(p P, s S) (S, Result)
- func (t *Table[K, P, S]) Close(err error)
- func (t *Table[K, P, S]) Done() <-chan struct{}
- func (t *Table[K, P, S]) Get(k K) (S, bool)
- func (t *Table[K, P, S]) Init(o TableOptions[K, P, S])
- func (t *Table[K, P, S]) Len() int
- func (t *Table[K, P, S]) Pending() int
- func (t *Table[K, P, S]) Remove(s S)
- func (t *Table[K, P, S]) Resolve(k K, prepare func(S)) S
- func (t *Table[K, P, S]) Room() bool
- func (t *Table[K, P, S]) SetIdle(d time.Duration)
- type TableOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Membership ¶
type Membership[K, P comparable] struct { // contains filtered or unexported fields }
Membership records a flow's registration and expiry position. The table owns it. A flow supplies its own zero Membership and keeps it for life.
type Table ¶
type Table[K, P, S comparable] struct { // contains filtered or unexported fields }
Table holds flows by primary key, optionally with a secondary peer index. Get uses a sync.Map and takes no lock. Mutations to a peer's keys and index take the same shard lock. Without an index, mutations shard by primary key. A zero Table is empty and cannot register flows. Accept waits for Close, and Close releases it with net.ErrClosed.
func (*Table[K, P, S]) Accept ¶
Accept waits for a new flow, skipping any closed meanwhile. It returns net.ErrClosed once the table is closed.
func (*Table[K, P, S]) AddOrBind ¶
AddOrBind looks up k, then binds a peer's unbound flow if prepare is supplied, then tries to add s to the backlog. It returns Exists when either lookup or binding found the flow. See Resolve for prepare.
func (*Table[K, P, S]) AddUnbound ¶
AddUnbound registers a flow that does not have a primary key yet. It succeeds only if p has no flows. An unbound flow holds a slot and is not delivered by Accept. A table without a peer index refuses it with Closed.
func (*Table[K, P, S]) Close ¶
Close refuses new flows, stops the idle timeout and shuts down all flows with err for reads. Calls after the first do nothing.
func (*Table[K, P, S]) Done ¶
func (t *Table[K, P, S]) Done() <-chan struct{}
Done returns a channel that Close closes.
func (*Table[K, P, S]) Init ¶
func (t *Table[K, P, S]) Init(o TableOptions[K, P, S])
Init sets t up. Call it once, before the other methods.
func (*Table[K, P, S]) Remove ¶
func (t *Table[K, P, S]) Remove(s S)
Remove removes s whether it has a primary key or is awaiting one. The registration record identifies its shard, peer and current key.
func (*Table[K, P, S]) Resolve ¶
func (t *Table[K, P, S]) Resolve(k K, prepare func(S)) S
Resolve returns the flow under k, or binds a peer's unbound flow to k. prepare configures that flow before it becomes visible under k. It runs under the shard lock and must be an internal operation that does not call back into the table or any user code.
type TableOptions ¶
type TableOptions[K, P, S comparable] struct { Queue func(S) *dgram.Queue // Shutdown closes a flow with an error for reads and removes it. // It must be safe to call more than once. Shutdown func(S, error) // Membership returns the flow's registration record. Membership func(S) *Membership[K, P] // HashKey selects the shard for a table without a peer index. HashKey func(maphash.Seed, K) uint64 // Peer and HashPeer enable indexing. Supply both or neither. Keys for // the same peer are assigned to the same shard. Peer func(K) P HashPeer func(maphash.Seed, P) uint64 // Epoch is the time base of the queues and their idle timeout. Nil // uses the system clock's epoch. Epoch *clock.Epoch // Backlog is the number of connections waiting for Accept, at least one. Backlog int // Limit bounds the number of connections held, including unbound flows. // A non-positive limit adds no bound. Limit int // Idle shuts down accepted flows with io.EOF after this much inactivity. // A non-positive duration keeps idle flows. Idle time.Duration }
TableOptions configures Table.Init.