relayedaddr.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package proto
  2. import (
  3. "net"
  4. "github.com/pion/stun"
  5. )
  6. // RelayedAddress implements XOR-RELAYED-ADDRESS attribute.
  7. //
  8. // It specifies the address and port that the server allocated to the
  9. // client. It is encoded in the same way as XOR-MAPPED-ADDRESS.
  10. //
  11. // RFC 5766 Section 14.5
  12. type RelayedAddress struct {
  13. IP net.IP
  14. Port int
  15. }
  16. func (a RelayedAddress) String() string {
  17. return stun.XORMappedAddress(a).String()
  18. }
  19. // AddTo adds XOR-PEER-ADDRESS to message.
  20. func (a RelayedAddress) AddTo(m *stun.Message) error {
  21. return stun.XORMappedAddress(a).AddToAs(m, stun.AttrXORRelayedAddress)
  22. }
  23. // GetFrom decodes XOR-PEER-ADDRESS from message.
  24. func (a *RelayedAddress) GetFrom(m *stun.Message) error {
  25. return (*stun.XORMappedAddress)(a).GetFromAs(m, stun.AttrXORRelayedAddress)
  26. }
  27. // XORRelayedAddress implements XOR-RELAYED-ADDRESS attribute.
  28. //
  29. // It specifies the address and port that the server allocated to the
  30. // client. It is encoded in the same way as XOR-MAPPED-ADDRESS.
  31. //
  32. // RFC 5766 Section 14.5
  33. type XORRelayedAddress = RelayedAddress