const.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. NATSymetric
  36. NATRestricted
  37. NATPortRestricted
  38. NATSymetricUDPFirewall
  39. )
  40. var natStr map[NATType]string
  41. func init() {
  42. natStr = map[NATType]string{
  43. NATError: "Test failed",
  44. NATUnknown: "Unexpected response from the STUN server",
  45. NATBlocked: "UDP is blocked",
  46. NATFull: "Full cone NAT",
  47. NATSymetric: "Symetric NAT",
  48. NATRestricted: "Restricted NAT",
  49. NATPortRestricted: "Port restricted NAT",
  50. NATNone: "Not behind a NAT",
  51. NATSymetricUDPFirewall: "Symetric UDP firewall",
  52. }
  53. }
  54. func (nat NATType) String() string {
  55. if s, ok := natStr[nat]; ok {
  56. return s
  57. }
  58. return "Unknown"
  59. }
  60. const (
  61. errorTryAlternate = 300
  62. errorBadRequest = 400
  63. errorUnauthorized = 401
  64. errorUnassigned402 = 402
  65. errorForbidden = 403
  66. errorUnknownAttribute = 420
  67. errorAllocationMismatch = 437
  68. errorStaleNonce = 438
  69. errorUnassigned439 = 439
  70. errorAddressFamilyNotSupported = 440
  71. errorWrongCredentials = 441
  72. errorUnsupportedTransportProtocol = 442
  73. errorPeerAddressFamilyMismatch = 443
  74. errorConnectionAlreadyExists = 446
  75. errorConnectionTimeoutOrFailure = 447
  76. errorAllocationQuotaReached = 486
  77. errorRoleConflict = 487
  78. errorServerError = 500
  79. errorInsufficientCapacity = 508
  80. )
  81. const (
  82. attributeFamilyIPv4 = 0x01
  83. attributeFamilyIPV6 = 0x02
  84. )
  85. const (
  86. attributeMappedAddress = 0x0001
  87. attributeResponseAddress = 0x0002
  88. attributeChangeRequest = 0x0003
  89. attributeSourceAddress = 0x0004
  90. attributeChangedAddress = 0x0005
  91. attributeUsername = 0x0006
  92. attributePassword = 0x0007
  93. attributeMessageIntegrity = 0x0008
  94. attributeErrorCode = 0x0009
  95. attributeUnknownAttributes = 0x000a
  96. attributeReflectedFrom = 0x000b
  97. attributeChannelNumber = 0x000c
  98. attributeLifetime = 0x000d
  99. attributeBandwidth = 0x0010
  100. attributeXorPeerAddress = 0x0012
  101. attributeData = 0x0013
  102. attributeRealm = 0x0014
  103. attributeNonce = 0x0015
  104. attributeXorRelayedAddress = 0x0016
  105. attributeRequestedAddressFamily = 0x0017
  106. attributeEvenPort = 0x0018
  107. attributeRequestedTransport = 0x0019
  108. attributeDontFragment = 0x001a
  109. attributeXorMappedAddress = 0x0020
  110. attributeTimerVal = 0x0021
  111. attributeReservationToken = 0x0022
  112. attributePriority = 0x0024
  113. attributeUseCandidate = 0x0025
  114. attributePadding = 0x0026
  115. attributeResponsePort = 0x0027
  116. attributeConnectionID = 0x002a
  117. attributeXorMappedAddressExp = 0x8020
  118. attributeSoftware = 0x8022
  119. attributeAlternateServer = 0x8023
  120. attributeCacheTimeout = 0x8027
  121. attributeFingerprint = 0x8028
  122. attributeIceControlled = 0x8029
  123. attributeIceControlling = 0x802a
  124. attributeResponseOrigin = 0x802b
  125. attributeOtherAddress = 0x802c
  126. attributeEcnCheckStun = 0x802d
  127. attributeCiscoFlowdata = 0xc000
  128. )
  129. const (
  130. typeBindingRequest = 0x0001
  131. typeBindingResponse = 0x0101
  132. typeBindingErrorResponse = 0x0111
  133. typeSharedSecretRequest = 0x0002
  134. typeSharedSecretResponse = 0x0102
  135. typeSharedErrorResponse = 0x0112
  136. typeAllocate = 0x0003
  137. typeAllocateResponse = 0x0103
  138. typeAllocateErrorResponse = 0x0113
  139. typeRefresh = 0x0004
  140. typeRefreshResponse = 0x0104
  141. typeRefreshErrorResponse = 0x0114
  142. typeSend = 0x0006
  143. typeSendResponse = 0x0106
  144. typeSendErrorResponse = 0x0116
  145. typeData = 0x0007
  146. typeDataResponse = 0x0107
  147. typeDataErrorResponse = 0x0117
  148. typeCreatePermisiion = 0x0008
  149. typeCreatePermisiionResponse = 0x0108
  150. typeCreatePermisiionErrorResponse = 0x0118
  151. typeChannelBinding = 0x0009
  152. typeChannelBindingResponse = 0x0109
  153. typeChannelBindingErrorResponse = 0x0119
  154. typeConnect = 0x000a
  155. typeConnectResponse = 0x010a
  156. typeConnectErrorResponse = 0x011a
  157. typeConnectionBind = 0x000b
  158. typeConnectionBindResponse = 0x010b
  159. typeConnectionBindErrorResponse = 0x011b
  160. typeConnectionAttempt = 0x000c
  161. typeConnectionAttemptResponse = 0x010c
  162. typeConnectionAttemptErrorResponse = 0x011c
  163. )