conn.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package udp
  2. import (
  3. "net/netip"
  4. "github.com/slackhq/nebula/config"
  5. )
  6. const MTU = 9001
  7. type EncReader func(
  8. addr netip.AddrPort,
  9. payload []byte,
  10. )
  11. type EncBatchReader func(
  12. addrs []netip.AddrPort,
  13. payloads [][]byte,
  14. count int,
  15. )
  16. type Conn interface {
  17. Rebind() error
  18. LocalAddr() (netip.AddrPort, error)
  19. ListenOut(r EncReader)
  20. ListenOutBatch(r EncBatchReader)
  21. WriteTo(b []byte, addr netip.AddrPort) error
  22. WriteMulti(packets [][]byte, addrs []netip.AddrPort) (int, error)
  23. ReloadConfig(c *config.C)
  24. BatchSize() int
  25. Close() error
  26. }
  27. type NoopConn struct{}
  28. func (NoopConn) Rebind() error {
  29. return nil
  30. }
  31. func (NoopConn) LocalAddr() (netip.AddrPort, error) {
  32. return netip.AddrPort{}, nil
  33. }
  34. func (NoopConn) ListenOut(_ EncReader) {
  35. return
  36. }
  37. func (NoopConn) ListenOutBatch(_ EncBatchReader) {
  38. return
  39. }
  40. func (NoopConn) WriteTo(_ []byte, _ netip.AddrPort) error {
  41. return nil
  42. }
  43. func (NoopConn) WriteMulti(_ [][]byte, _ []netip.AddrPort) (int, error) {
  44. return 0, nil
  45. }
  46. func (NoopConn) ReloadConfig(_ *config.C) {
  47. return
  48. }
  49. func (NoopConn) BatchSize() int {
  50. return 1
  51. }
  52. func (NoopConn) Close() error {
  53. return nil
  54. }