forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shadowsockets fullcone outbound support
- Loading branch information
1 parent
cdfef7e
commit d068b60
Showing
4 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package udp | ||
|
||
import ( | ||
gonet "net" | ||
|
||
"github.com/v2fly/v2ray-core/v4/common/signal" | ||
"github.com/v2fly/v2ray-core/v4/transport/internet" | ||
) | ||
|
||
type dataHandler func(content []byte, address gonet.Addr) | ||
|
||
type copyHandler struct { | ||
onData []dataHandler | ||
} | ||
|
||
type CopyOption func(*copyHandler) | ||
|
||
func CopyPacketConn(dst internet.AbstractPacketConnWriter, src internet.AbstractPacketConnReader, options ...CopyOption) error { | ||
var handler copyHandler | ||
for _, option := range options { | ||
option(&handler) | ||
} | ||
var buffer [2048]byte | ||
for { | ||
n, addr, err := src.ReadFrom(buffer[:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, handler := range handler.onData { | ||
handler(buffer[:n], addr) | ||
} | ||
|
||
n, err = dst.WriteTo(buffer[:n], addr) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func UpdateActivity(timer signal.ActivityUpdater) CopyOption { | ||
return func(handler *copyHandler) { | ||
handler.onData = append(handler.onData, func(content []byte, address gonet.Addr) { | ||
timer.Update() | ||
}) | ||
} | ||
} |