feat:多跳(B->D->C->A)功能
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
func main() {
|
||||
peerID := flag.String("id", "peer-a", "peer identity")
|
||||
serverAddr := flag.String("server", "127.0.0.1:9002", "KCP server address")
|
||||
relayVia := flag.String("relay-via", "", "optional UDP relay address used to reach the KCP server")
|
||||
targetPeer := flag.String("to", "", "optional target peer for one outgoing message")
|
||||
text := flag.String("text", "", "optional text to send after connecting")
|
||||
filePath := flag.String("file", "", "optional file path to send after connecting")
|
||||
@@ -66,6 +67,9 @@ func main() {
|
||||
if *bindDevice != "" {
|
||||
clientOptions = append(clientOptions, peerpkg.WithBindDevice(*bindDevice))
|
||||
}
|
||||
if *relayVia != "" {
|
||||
clientOptions = append(clientOptions, peerpkg.WithKCPDialAddress(*relayVia))
|
||||
}
|
||||
|
||||
client, err := peerpkg.DialKCP(*serverAddr, *peerID, clientOptions...)
|
||||
if err != nil {
|
||||
@@ -73,7 +77,11 @@ func main() {
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
log.Printf("connected to %s as %s (KCP)", *serverAddr, client.ID())
|
||||
if *relayVia != "" {
|
||||
log.Printf("connected to %s via relay %s as %s (KCP)", *serverAddr, *relayVia, client.ID())
|
||||
} else {
|
||||
log.Printf("connected to %s as %s (KCP)", *serverAddr, client.ID())
|
||||
}
|
||||
|
||||
receiveErr := make(chan error, 1)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user