-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b4e7d9
commit 012cd28
Showing
8 changed files
with
191 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build !js | ||
// +build !js | ||
|
||
package ice | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/pion/logging" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAgentActiveTCP(t *testing.T) { | ||
r := require.New(t) | ||
|
||
const port = 7686 | ||
|
||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{ | ||
IP: net.IPv4(127, 0, 0, 1), | ||
Port: port, | ||
}) | ||
r.NoError(err) | ||
defer func() { | ||
_ = listener.Close() | ||
}() | ||
|
||
loggerFactory := logging.NewDefaultLoggerFactory() | ||
loggerFactory.DefaultLogLevel.Set(logging.LogLevelTrace) | ||
|
||
tcpMux := NewTCPMuxDefault(TCPMuxParams{ | ||
Listener: listener, | ||
Logger: loggerFactory.NewLogger("passive-ice-tcp-mux"), | ||
ReadBufferSize: 20, | ||
}) | ||
|
||
defer func() { | ||
_ = tcpMux.Close() | ||
}() | ||
|
||
r.NotNil(tcpMux.LocalAddr(), "tcpMux.LocalAddr() is nil") | ||
|
||
passiveAgent, err := NewAgent(&AgentConfig{ | ||
TCPMux: tcpMux, | ||
CandidateTypes: []CandidateType{CandidateTypeHost}, | ||
NetworkTypes: []NetworkType{NetworkTypeTCP4}, | ||
LoggerFactory: loggerFactory, | ||
IncludeLoopback: true, | ||
}) | ||
r.NoError(err) | ||
r.NotNil(passiveAgent) | ||
|
||
activeAgent, err := NewAgent(&AgentConfig{ | ||
CandidateTypes: []CandidateType{CandidateTypeHost}, | ||
NetworkTypes: []NetworkType{NetworkTypeTCP4}, | ||
LoggerFactory: loggerFactory, | ||
}) | ||
r.NoError(err) | ||
r.NotNil(activeAgent) | ||
|
||
passiveAgentConn, activeAgenConn := connect(passiveAgent, activeAgent) | ||
r.NotNil(passiveAgentConn) | ||
r.NotNil(activeAgenConn) | ||
|
||
pair := passiveAgent.getSelectedPair() | ||
r.NotNil(pair) | ||
r.Equal(port, pair.Local.Port()) | ||
|
||
data := []byte("hello world") | ||
_, err = passiveAgentConn.Write(data) | ||
r.NoError(err) | ||
|
||
buffer := make([]byte, 1024) | ||
n, err := activeAgenConn.Read(buffer) | ||
r.NoError(err) | ||
r.Equal(data, buffer[:n]) | ||
|
||
data2 := []byte("hello world 2") | ||
_, err = activeAgenConn.Write(data2) | ||
r.NoError(err) | ||
|
||
n, err = passiveAgentConn.Read(buffer) | ||
r.NoError(err) | ||
r.Equal(data2, buffer[:n]) | ||
|
||
r.NoError(activeAgenConn.Close()) | ||
r.NoError(passiveAgentConn.Close()) | ||
} |
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
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