From 28a9a2ef872705a5b9c2c5f7cc99f88a5e033c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Mon, 15 Apr 2024 14:12:24 +0200 Subject: [PATCH] Move receiverCreator to new file --- iface/bind/bind.go | 13 ++----------- iface/bind/receiver_creator.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 iface/bind/receiver_creator.go diff --git a/iface/bind/bind.go b/iface/bind/bind.go index 00af25f67..35ba27bc0 100644 --- a/iface/bind/bind.go +++ b/iface/bind/bind.go @@ -13,14 +13,6 @@ import ( wgConn "golang.zx2c4.com/wireguard/conn" ) -type receiverCreator struct { - iceBind *ICEBind -} - -func (rc receiverCreator) CreateIPv4ReceiverFn(msgPool *sync.Pool, pc *ipv4.PacketConn, conn *net.UDPConn) wgConn.ReceiveFunc { - return rc.iceBind.createIPv4ReceiverFn(msgPool, pc, conn) -} - type ICEBind struct { *wgConn.StdNetBind @@ -35,9 +27,8 @@ func NewICEBind(transportNet transport.Net) *ICEBind { transportNet: transportNet, } - rc := receiverCreator{ - ib, - } + rc := newReceiverCreator(ib) + ib.StdNetBind = wgConn.NewStdNetBindWithReceiverCreator(rc) return ib } diff --git a/iface/bind/receiver_creator.go b/iface/bind/receiver_creator.go new file mode 100644 index 000000000..b205c4d5f --- /dev/null +++ b/iface/bind/receiver_creator.go @@ -0,0 +1,23 @@ +package bind + +import ( + "net" + "sync" + + "golang.org/x/net/ipv4" + wgConn "golang.zx2c4.com/wireguard/conn" +) + +type receiverCreator struct { + iceBind *ICEBind +} + +func newReceiverCreator(iceBind *ICEBind) receiverCreator { + return receiverCreator{ + iceBind: iceBind, + } +} + +func (rc receiverCreator) CreateIPv4ReceiverFn(msgPool *sync.Pool, pc *ipv4.PacketConn, conn *net.UDPConn) wgConn.ReceiveFunc { + return rc.iceBind.createIPv4ReceiverFn(msgPool, pc, conn) +}