peeraddr.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package proto
  2. import (
  3. "net"
  4. "github.com/pion/stun"
  5. )
  6. // PeerAddress implements XOR-PEER-ADDRESS attribute.
  7. //
  8. // The XOR-PEER-ADDRESS specifies the address and port of the peer as
  9. // seen from the TURN server. (For example, the peer's server-reflexive
  10. // transport address if the peer is behind a NAT.)
  11. //
  12. // RFC 5766 Section 14.3
  13. type PeerAddress struct {
  14. IP net.IP
  15. Port int
  16. }
  17. func (a PeerAddress) String() string {
  18. return stun.XORMappedAddress(a).String()
  19. }
  20. // AddTo adds XOR-PEER-ADDRESS to message.
  21. func (a PeerAddress) AddTo(m *stun.Message) error {
  22. return stun.XORMappedAddress(a).AddToAs(m, stun.AttrXORPeerAddress)
  23. }
  24. // GetFrom decodes XOR-PEER-ADDRESS from message.
  25. func (a *PeerAddress) GetFrom(m *stun.Message) error {
  26. return (*stun.XORMappedAddress)(a).GetFromAs(m, stun.AttrXORPeerAddress)
  27. }
  28. // XORPeerAddress implements XOR-PEER-ADDRESS attribute.
  29. //
  30. // The XOR-PEER-ADDRESS specifies the address and port of the peer as
  31. // seen from the TURN server. (For example, the peer's server-reflexive
  32. // transport address if the peer is behind a NAT.)
  33. //
  34. // RFC 5766 Section 14.3
  35. type XORPeerAddress = PeerAddress