2023-06-03 21:40:09 +08:00
|
|
|
package nat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/common/atomic"
|
|
|
|
C "github.com/metacubex/mihomo/constant"
|
2023-06-03 21:40:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type writeBackProxy struct {
|
|
|
|
wb atomic.TypedValue[C.WriteBack]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *writeBackProxy) WriteBack(b []byte, addr net.Addr) (n int, err error) {
|
|
|
|
return w.wb.Load().WriteBack(b, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *writeBackProxy) UpdateWriteBack(wb C.WriteBack) {
|
|
|
|
w.wb.Store(wb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWriteBackProxy(wb C.WriteBack) C.WriteBackProxy {
|
|
|
|
w := &writeBackProxy{}
|
|
|
|
w.UpdateWriteBack(wb)
|
|
|
|
return w
|
|
|
|
}
|