mirror of
https://github.com/gortc/stun.git
synced 2025-10-04 16:22:42 +08:00
all: init TURN and ICE
This commit is contained in:
@@ -10,6 +10,7 @@ const (
|
|||||||
CodeUnauthorised ErrorCode = 401
|
CodeUnauthorised ErrorCode = 401
|
||||||
CodeUnknownAttribute ErrorCode = 420
|
CodeUnknownAttribute ErrorCode = 420
|
||||||
CodeStaleNonce ErrorCode = 428
|
CodeStaleNonce ErrorCode = 428
|
||||||
|
CodeRoleConflict ErrorCode = 478
|
||||||
CodeServerError ErrorCode = 500
|
CodeServerError ErrorCode = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ func (c ErrorCode) Reason() string {
|
|||||||
return "Stale Nonce"
|
return "Stale Nonce"
|
||||||
case CodeServerError:
|
case CodeServerError:
|
||||||
return "Server Error"
|
return "Server Error"
|
||||||
|
case CodeRoleConflict:
|
||||||
|
return "Role conflict"
|
||||||
default:
|
default:
|
||||||
return "Unknown Error"
|
return "Unknown Error"
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ func TestErrorCode_Reason(t *testing.T) {
|
|||||||
CodeUnauthorised,
|
CodeUnauthorised,
|
||||||
CodeUnknownAttribute,
|
CodeUnknownAttribute,
|
||||||
CodeStaleNonce,
|
CodeStaleNonce,
|
||||||
|
CodeRoleConflict,
|
||||||
CodeServerError,
|
CodeServerError,
|
||||||
}
|
}
|
||||||
for _, code := range codes {
|
for _, code := range codes {
|
||||||
|
@@ -55,6 +55,27 @@ const (
|
|||||||
AttrFingerprint AttrType = 0x8028 // FINGERPRINT
|
AttrFingerprint AttrType = 0x8028 // FINGERPRINT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Attributes from RFC 5245 ICE.
|
||||||
|
const (
|
||||||
|
AttrPriority AttrType = 0x0024 // PRIORITY
|
||||||
|
AttrUseCandidate AttrType = 0x0025 // USE-CANDIDATE
|
||||||
|
AttrICEControlled AttrType = 0x8029 // ICE-CONTROLLED
|
||||||
|
AttrICEControlling AttrType = 0x802A // ICE-CONTROLLING
|
||||||
|
)
|
||||||
|
|
||||||
|
// Attributes from RFC 5766 TURN.
|
||||||
|
const (
|
||||||
|
AttrChannelNumber AttrType = 0x000C // CHANNEL-NUMBER
|
||||||
|
AttrLifetime AttrType = 0x000D // LIFETIME
|
||||||
|
AttrXORPeerAddress AttrType = 0x0012 // XOR-PEER-ADDRESS
|
||||||
|
AttrData AttrType = 0x0013 // DATA
|
||||||
|
AttrXORRelayedAddress AttrType = 0x0016 // XOR-RELAYED-ADDRESS
|
||||||
|
AttrEvenPort AttrType = 0x0018 // EVEN-PORT
|
||||||
|
AttrRequestedTransport AttrType = 0x0019 // REQUESTED-TRANSPORT
|
||||||
|
AttrDontFragment AttrType = 0x001A // DONT-FRAGMENT
|
||||||
|
AttrReservationToken AttrType = 0x0022 // RESERVATION-TOKEN
|
||||||
|
)
|
||||||
|
|
||||||
// Value returns uint16 representation of attribute type.
|
// Value returns uint16 representation of attribute type.
|
||||||
func (t AttrType) Value() uint16 {
|
func (t AttrType) Value() uint16 {
|
||||||
return uint16(t)
|
return uint16(t)
|
||||||
@@ -84,6 +105,32 @@ func (t AttrType) String() string {
|
|||||||
return "ALTERNATE-SERVER"
|
return "ALTERNATE-SERVER"
|
||||||
case AttrFingerprint:
|
case AttrFingerprint:
|
||||||
return "FINGERPRINT"
|
return "FINGERPRINT"
|
||||||
|
case AttrPriority:
|
||||||
|
return "PRIORITY"
|
||||||
|
case AttrUseCandidate:
|
||||||
|
return "USE-CANDIDATE"
|
||||||
|
case AttrICEControlled:
|
||||||
|
return "ICE-CONTROLLED"
|
||||||
|
case AttrICEControlling:
|
||||||
|
return "ICE-CONTROLLING"
|
||||||
|
case AttrChannelNumber:
|
||||||
|
return "CHANNEL-NUMBER"
|
||||||
|
case AttrLifetime:
|
||||||
|
return "LIFETIME"
|
||||||
|
case AttrXORPeerAddress:
|
||||||
|
return "XOR-PEER-ADDRESS"
|
||||||
|
case AttrData:
|
||||||
|
return "DATA"
|
||||||
|
case AttrXORRelayedAddress:
|
||||||
|
return "XOR-RELAYED-ADDRESS"
|
||||||
|
case AttrEvenPort:
|
||||||
|
return "EVEN-PORT"
|
||||||
|
case AttrRequestedTransport:
|
||||||
|
return "REQUESTED-TRANSPORT"
|
||||||
|
case AttrDontFragment:
|
||||||
|
return "DONT-FRAGMENT"
|
||||||
|
case AttrReservationToken:
|
||||||
|
return "RESERVATION-TOKEN"
|
||||||
default:
|
default:
|
||||||
// just return hex representation of unknown attribute type
|
// just return hex representation of unknown attribute type
|
||||||
return "0x" + strconv.FormatUint(uint64(t), 16)
|
return "0x" + strconv.FormatUint(uint64(t), 16)
|
||||||
|
20
stun.go
20
stun.go
@@ -432,13 +432,31 @@ type Method uint16
|
|||||||
|
|
||||||
// Possible methods for STUN Message.
|
// Possible methods for STUN Message.
|
||||||
const (
|
const (
|
||||||
MethodBinding Method = 0x01 // 0b000000000001
|
MethodBinding Method = 0x001
|
||||||
|
MethodAllocate Method = 0x003
|
||||||
|
MethodRefresh Method = 0x004
|
||||||
|
MethodSend Method = 0x006
|
||||||
|
MethodData Method = 0x007
|
||||||
|
MethodCreatePermission Method = 0x008
|
||||||
|
MethodChannelBind Method = 0x009
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m Method) String() string {
|
func (m Method) String() string {
|
||||||
switch m {
|
switch m {
|
||||||
case MethodBinding:
|
case MethodBinding:
|
||||||
return "binding"
|
return "binding"
|
||||||
|
case MethodAllocate:
|
||||||
|
return "allocate"
|
||||||
|
case MethodRefresh:
|
||||||
|
return "refresh"
|
||||||
|
case MethodSend:
|
||||||
|
return "send"
|
||||||
|
case MethodData:
|
||||||
|
return "data"
|
||||||
|
case MethodCreatePermission:
|
||||||
|
return "create permission"
|
||||||
|
case MethodChannelBind:
|
||||||
|
return "channel bind"
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("0x%s", strconv.FormatUint(uint64(m), 16))
|
return fmt.Sprintf("0x%s", strconv.FormatUint(uint64(m), 16))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user