| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | package netimport (	"net")// Destination represents a network destination including address and protocol (tcp / udp).type Destination struct {	Network Network	Address Address	Port    Port}func DestinationFromAddr(addr net.Addr) Destination {	switch addr := addr.(type) {	case *net.TCPAddr:		return TCPDestination(IPAddress(addr.IP), Port(addr.Port))	case *net.UDPAddr:		return UDPDestination(IPAddress(addr.IP), Port(addr.Port))	default:		panic("Unknown address type.")	}}// TCPDestination creates a TCP destination with given addressfunc TCPDestination(address Address, port Port) Destination {	return Destination{		Network: Network_TCP,		Address: address,		Port:    port,	}}// UDPDestination creates a UDP destination with given addressfunc UDPDestination(address Address, port Port) Destination {	return Destination{		Network: Network_UDP,		Address: address,		Port:    port,	}}func (this Destination) NetAddr() string {	return this.Address.String() + ":" + this.Port.String()}func (this Destination) String() string {	return this.Network.UrlPrefix() + ":" + this.NetAddr()}func (this Destination) Equals(another Destination) bool {	return this.Network == another.Network && this.Port == another.Port && this.Address.Equals(another.Address)}func (this *Endpoint) AsDestination() Destination {	return Destination{		Network: this.Network,		Address: this.Address.AsAddress(),		Port:    Port(this.Port),	}}
 |