const.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2013, Cong Ding. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Author: Cong Ding <[email protected]>
  16. package stun
  17. // Default server address and client name.
  18. const (
  19. DefaultServerAddr = "stun.ekiga.net:3478"
  20. DefaultSoftwareName = "StunClient"
  21. )
  22. const (
  23. magicCookie = 0x2112A442
  24. fingerprint = 0x5354554e
  25. )
  26. // NATType is the type of NAT described by int.
  27. type NATType int
  28. // NAT types.
  29. const (
  30. NATError NATType = iota
  31. NATUnknown
  32. NATNone
  33. NATBlocked
  34. NATFull
  35. NATSymmetric
  36. NATRestricted
  37. NATPortRestricted
  38. NATSymmetricUDPFirewall
  39. // Deprecated spellings of these constants
  40. NATSymetric = NATSymmetric
  41. NATSymetricUDPFirewall = NATSymmetricUDPFirewall
  42. )
  43. var natStr map[NATType]string
  44. func init() {
  45. natStr = map[NATType]string{
  46. NATError: "Test failed",
  47. NATUnknown: "Unexpected response from the STUN server",
  48. NATBlocked: "UDP is blocked",
  49. NATFull: "Full cone NAT",
  50. NATSymmetric: "Symmetric NAT",
  51. NATRestricted: "Restricted NAT",
  52. NATPortRestricted: "Port restricted NAT",
  53. NATNone: "Not behind a NAT",
  54. NATSymmetricUDPFirewall: "Symmetric UDP firewall",
  55. }
  56. }
  57. func (nat NATType) String() string {
  58. if s, ok := natStr[nat]; ok {
  59. return s
  60. }
  61. return "Unknown"
  62. }
  63. const (
  64. errorTryAlternate = 300
  65. errorBadRequest = 400
  66. errorUnauthorized = 401
  67. errorUnassigned402 = 402
  68. errorForbidden = 403
  69. errorUnknownAttribute = 420
  70. errorAllocationMismatch = 437
  71. errorStaleNonce = 438
  72. errorUnassigned439 = 439
  73. errorAddressFamilyNotSupported = 440
  74. errorWrongCredentials = 441
  75. errorUnsupportedTransportProtocol = 442
  76. errorPeerAddressFamilyMismatch = 443
  77. errorConnectionAlreadyExists = 446
  78. errorConnectionTimeoutOrFailure = 447
  79. errorAllocationQuotaReached = 486
  80. errorRoleConflict = 487
  81. errorServerError = 500
  82. errorInsufficientCapacity = 508
  83. )
  84. const (
  85. attributeFamilyIPv4 = 0x01
  86. attributeFamilyIPV6 = 0x02
  87. )
  88. const (
  89. attributeMappedAddress = 0x0001
  90. attributeResponseAddress = 0x0002
  91. attributeChangeRequest = 0x0003
  92. attributeSourceAddress = 0x0004
  93. attributeChangedAddress = 0x0005
  94. attributeUsername = 0x0006
  95. attributePassword = 0x0007
  96. attributeMessageIntegrity = 0x0008
  97. attributeErrorCode = 0x0009
  98. attributeUnknownAttributes = 0x000a
  99. attributeReflectedFrom = 0x000b
  100. attributeChannelNumber = 0x000c
  101. attributeLifetime = 0x000d
  102. attributeBandwidth = 0x0010
  103. attributeXorPeerAddress = 0x0012
  104. attributeData = 0x0013
  105. attributeRealm = 0x0014
  106. attributeNonce = 0x0015
  107. attributeXorRelayedAddress = 0x0016
  108. attributeRequestedAddressFamily = 0x0017
  109. attributeEvenPort = 0x0018
  110. attributeRequestedTransport = 0x0019
  111. attributeDontFragment = 0x001a
  112. attributeXorMappedAddress = 0x0020
  113. attributeTimerVal = 0x0021
  114. attributeReservationToken = 0x0022
  115. attributePriority = 0x0024
  116. attributeUseCandidate = 0x0025
  117. attributePadding = 0x0026
  118. attributeResponsePort = 0x0027
  119. attributeConnectionID = 0x002a
  120. attributeXorMappedAddressExp = 0x8020
  121. attributeSoftware = 0x8022
  122. attributeAlternateServer = 0x8023
  123. attributeCacheTimeout = 0x8027
  124. attributeFingerprint = 0x8028
  125. attributeIceControlled = 0x8029
  126. attributeIceControlling = 0x802a
  127. attributeResponseOrigin = 0x802b
  128. attributeOtherAddress = 0x802c
  129. attributeEcnCheckStun = 0x802d
  130. attributeCiscoFlowdata = 0xc000
  131. )
  132. const (
  133. typeBindingRequest = 0x0001
  134. typeBindingResponse = 0x0101
  135. typeBindingErrorResponse = 0x0111
  136. typeSharedSecretRequest = 0x0002
  137. typeSharedSecretResponse = 0x0102
  138. typeSharedErrorResponse = 0x0112
  139. typeAllocate = 0x0003
  140. typeAllocateResponse = 0x0103
  141. typeAllocateErrorResponse = 0x0113
  142. typeRefresh = 0x0004
  143. typeRefreshResponse = 0x0104
  144. typeRefreshErrorResponse = 0x0114
  145. typeSend = 0x0006
  146. typeSendResponse = 0x0106
  147. typeSendErrorResponse = 0x0116
  148. typeData = 0x0007
  149. typeDataResponse = 0x0107
  150. typeDataErrorResponse = 0x0117
  151. typeCreatePermisiion = 0x0008
  152. typeCreatePermisiionResponse = 0x0108
  153. typeCreatePermisiionErrorResponse = 0x0118
  154. typeChannelBinding = 0x0009
  155. typeChannelBindingResponse = 0x0109
  156. typeChannelBindingErrorResponse = 0x0119
  157. typeConnect = 0x000a
  158. typeConnectResponse = 0x010a
  159. typeConnectErrorResponse = 0x011a
  160. typeConnectionBind = 0x000b
  161. typeConnectionBindResponse = 0x010b
  162. typeConnectionBindErrorResponse = 0x011b
  163. typeConnectionAttempt = 0x000c
  164. typeConnectionAttemptResponse = 0x010c
  165. typeConnectionAttemptErrorResponse = 0x011c
  166. )