42 lines
890 B
Go
42 lines
890 B
Go
package peer
|
|
|
|
import (
|
|
"net/netip"
|
|
"vppn/m"
|
|
)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// A route is used by a peer to send or receive packets. A peer won't send
|
|
// packets on a route that isn't up, but will process incoming packets on
|
|
// that route.
|
|
type route struct {
|
|
PeerIP byte
|
|
Up bool
|
|
Mediator bool
|
|
EncSharedKey []byte // Shared key for encoding / decoding packets.
|
|
Addr netip.AddrPort
|
|
useMediator bool
|
|
}
|
|
|
|
type peerUpdate struct {
|
|
PeerIP byte
|
|
*m.Peer // nil => delete.
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Wrapper for routing packets.
|
|
type wrapper[T any] struct {
|
|
T T
|
|
Nonce Nonce
|
|
SrcAddr netip.AddrPort
|
|
}
|
|
|
|
func newWrapper[T any](srcAddr netip.AddrPort, nonce Nonce) wrapper[T] {
|
|
return wrapper[T]{
|
|
SrcAddr: srcAddr,
|
|
Nonce: nonce,
|
|
}
|
|
}
|