-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Showing
9 changed files
with
219 additions
and
24 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
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,67 @@ | ||
package webrtc | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
var supportedNetworkTypes = []NetworkType{ | ||
NetworkTypeUDP4, | ||
NetworkTypeUDP6, | ||
// NetworkTypeTCP4, // Not supported yet | ||
// NetworkTypeTCP6, // Not supported yet | ||
} | ||
|
||
// NetworkType represents the type of network | ||
type NetworkType int | ||
|
||
const ( | ||
// NetworkTypeUDP4 indicates UDP over IPv4. | ||
NetworkTypeUDP4 NetworkType = iota + 1 | ||
|
||
// NetworkTypeUDP6 indicates UDP over IPv6. | ||
NetworkTypeUDP6 | ||
|
||
// NetworkTypeTCP4 indicates TCP over IPv4. | ||
NetworkTypeTCP4 | ||
|
||
// NetworkTypeTCP6 indicates TCP over IPv6. | ||
NetworkTypeTCP6 | ||
) | ||
|
||
// This is done this way because of a linter. | ||
const ( | ||
networkTypeUDP4Str = "udp4" | ||
networkTypeUDP6Str = "udp6" | ||
networkTypeTCP4Str = "tcp4" | ||
networkTypeTCP6Str = "tcp6" | ||
) | ||
|
||
func (t NetworkType) String() string { | ||
switch t { | ||
case NetworkTypeUDP4: | ||
return networkTypeUDP4Str | ||
case NetworkTypeUDP6: | ||
return networkTypeUDP6Str | ||
case NetworkTypeTCP4: | ||
return networkTypeTCP4Str | ||
case NetworkTypeTCP6: | ||
return networkTypeTCP6Str | ||
default: | ||
return ErrUnknownType.Error() | ||
} | ||
} | ||
|
||
func newNetworkType(raw string) (NetworkType, error) { | ||
switch raw { | ||
case networkTypeUDP4Str: | ||
return NetworkTypeUDP4, nil | ||
case networkTypeUDP6Str: | ||
return NetworkTypeUDP6, nil | ||
case networkTypeTCP4Str: | ||
return NetworkTypeTCP4, nil | ||
case networkTypeTCP6Str: | ||
return NetworkTypeTCP6, nil | ||
default: | ||
return NetworkType(Unknown), fmt.Errorf("unknown network type: %s", raw) | ||
} | ||
} |
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,54 @@ | ||
package webrtc | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNetworkType_String(t *testing.T) { | ||
testCases := []struct { | ||
cType NetworkType | ||
expectedString string | ||
}{ | ||
{NetworkType(Unknown), unknownStr}, | ||
{NetworkTypeUDP4, "udp4"}, | ||
{NetworkTypeUDP6, "udp6"}, | ||
{NetworkTypeTCP4, "tcp4"}, | ||
{NetworkTypeTCP6, "tcp6"}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
assert.Equal(t, | ||
testCase.expectedString, | ||
testCase.cType.String(), | ||
"testCase: %d %v", i, testCase, | ||
) | ||
} | ||
} | ||
|
||
func TestNetworkType(t *testing.T) { | ||
testCases := []struct { | ||
typeString string | ||
shouldFail bool | ||
expectedType NetworkType | ||
}{ | ||
{unknownStr, true, NetworkType(Unknown)}, | ||
{"udp4", false, NetworkTypeUDP4}, | ||
{"udp6", false, NetworkTypeUDP6}, | ||
{"tcp4", false, NetworkTypeTCP4}, | ||
{"tcp6", false, NetworkTypeTCP6}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actual, err := newNetworkType(testCase.typeString) | ||
if (err != nil) != testCase.shouldFail { | ||
t.Error(err) | ||
} | ||
assert.Equal(t, | ||
testCase.expectedType, | ||
actual, | ||
"testCase: %d %v", i, testCase, | ||
) | ||
} | ||
} |
Oops, something went wrong.