File: const.go

package info (click to toggle)
golang-github-ccding-go-stun 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 156 kB
  • sloc: makefile: 5
file content (178 lines) | stat: -rw-r--r-- 5,980 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2013, Cong Ding. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Cong Ding <dinggnu@gmail.com>

package stun

// Default server address and client name.
const (
	DefaultServerAddr   = "stun.ekiga.net:3478"
	DefaultSoftwareName = "StunClient"
)

const (
	magicCookie = 0x2112A442
	fingerprint = 0x5354554e
)

// NATType is the type of NAT described by int.
type NATType int

// NAT types.
const (
	NATError NATType = iota
	NATUnknown
	NATNone
	NATBlocked
	NATFull
	NATSymmetric
	NATRestricted
	NATPortRestricted
	NATSymmetricUDPFirewall

	// Deprecated spellings of these constants
	NATSymetric            = NATSymmetric
	NATSymetricUDPFirewall = NATSymmetricUDPFirewall
)

var natStr map[NATType]string

func init() {
	natStr = map[NATType]string{
		NATError:                "Test failed",
		NATUnknown:              "Unexpected response from the STUN server",
		NATBlocked:              "UDP is blocked",
		NATFull:                 "Full cone NAT",
		NATSymmetric:            "Symmetric NAT",
		NATRestricted:           "Restricted NAT",
		NATPortRestricted:       "Port restricted NAT",
		NATNone:                 "Not behind a NAT",
		NATSymmetricUDPFirewall: "Symmetric UDP firewall",
	}
}

func (nat NATType) String() string {
	if s, ok := natStr[nat]; ok {
		return s
	}
	return "Unknown"
}

const (
	errorTryAlternate                 = 300
	errorBadRequest                   = 400
	errorUnauthorized                 = 401
	errorUnassigned402                = 402
	errorForbidden                    = 403
	errorUnknownAttribute             = 420
	errorAllocationMismatch           = 437
	errorStaleNonce                   = 438
	errorUnassigned439                = 439
	errorAddressFamilyNotSupported    = 440
	errorWrongCredentials             = 441
	errorUnsupportedTransportProtocol = 442
	errorPeerAddressFamilyMismatch    = 443
	errorConnectionAlreadyExists      = 446
	errorConnectionTimeoutOrFailure   = 447
	errorAllocationQuotaReached       = 486
	errorRoleConflict                 = 487
	errorServerError                  = 500
	errorInsufficientCapacity         = 508
)
const (
	attributeFamilyIPv4 = 0x01
	attributeFamilyIPV6 = 0x02
)

const (
	attributeMappedAddress          = 0x0001
	attributeResponseAddress        = 0x0002
	attributeChangeRequest          = 0x0003
	attributeSourceAddress          = 0x0004
	attributeChangedAddress         = 0x0005
	attributeUsername               = 0x0006
	attributePassword               = 0x0007
	attributeMessageIntegrity       = 0x0008
	attributeErrorCode              = 0x0009
	attributeUnknownAttributes      = 0x000a
	attributeReflectedFrom          = 0x000b
	attributeChannelNumber          = 0x000c
	attributeLifetime               = 0x000d
	attributeBandwidth              = 0x0010
	attributeXorPeerAddress         = 0x0012
	attributeData                   = 0x0013
	attributeRealm                  = 0x0014
	attributeNonce                  = 0x0015
	attributeXorRelayedAddress      = 0x0016
	attributeRequestedAddressFamily = 0x0017
	attributeEvenPort               = 0x0018
	attributeRequestedTransport     = 0x0019
	attributeDontFragment           = 0x001a
	attributeXorMappedAddress       = 0x0020
	attributeTimerVal               = 0x0021
	attributeReservationToken       = 0x0022
	attributePriority               = 0x0024
	attributeUseCandidate           = 0x0025
	attributePadding                = 0x0026
	attributeResponsePort           = 0x0027
	attributeConnectionID           = 0x002a
	attributeXorMappedAddressExp    = 0x8020
	attributeSoftware               = 0x8022
	attributeAlternateServer        = 0x8023
	attributeCacheTimeout           = 0x8027
	attributeFingerprint            = 0x8028
	attributeIceControlled          = 0x8029
	attributeIceControlling         = 0x802a
	attributeResponseOrigin         = 0x802b
	attributeOtherAddress           = 0x802c
	attributeEcnCheckStun           = 0x802d
	attributeCiscoFlowdata          = 0xc000
)

const (
	typeBindingRequest                 = 0x0001
	typeBindingResponse                = 0x0101
	typeBindingErrorResponse           = 0x0111
	typeSharedSecretRequest            = 0x0002
	typeSharedSecretResponse           = 0x0102
	typeSharedErrorResponse            = 0x0112
	typeAllocate                       = 0x0003
	typeAllocateResponse               = 0x0103
	typeAllocateErrorResponse          = 0x0113
	typeRefresh                        = 0x0004
	typeRefreshResponse                = 0x0104
	typeRefreshErrorResponse           = 0x0114
	typeSend                           = 0x0006
	typeSendResponse                   = 0x0106
	typeSendErrorResponse              = 0x0116
	typeData                           = 0x0007
	typeDataResponse                   = 0x0107
	typeDataErrorResponse              = 0x0117
	typeCreatePermisiion               = 0x0008
	typeCreatePermisiionResponse       = 0x0108
	typeCreatePermisiionErrorResponse  = 0x0118
	typeChannelBinding                 = 0x0009
	typeChannelBindingResponse         = 0x0109
	typeChannelBindingErrorResponse    = 0x0119
	typeConnect                        = 0x000a
	typeConnectResponse                = 0x010a
	typeConnectErrorResponse           = 0x011a
	typeConnectionBind                 = 0x000b
	typeConnectionBindResponse         = 0x010b
	typeConnectionBindErrorResponse    = 0x011b
	typeConnectionAttempt              = 0x000c
	typeConnectionAttemptResponse      = 0x010c
	typeConnectionAttemptErrorResponse = 0x011c
)