Documentation ¶
Overview ¶
Package vnet provides a virtual network layer for pion
Index ¶
- type Chunk
- type ChunkFilter
- type Dialer
- type EndpointDependencyType
- type Interface
- type InterfaceBase
- type NATMode
- type NATType
- type NIC
- type Net
- func (n *Net) CreateDialer(dialer *net.Dialer) Dialer
- func (n *Net) Dial(network, address string) (net.Conn, error)
- func (n *Net) DialUDP(network string, laddr, raddr *net.UDPAddr) (UDPPacketConn, error)
- func (n *Net) InterfaceByName(name string) (*Interface, error)
- func (n *Net) Interfaces() ([]*Interface, error)
- func (n *Net) IsVirtual() bool
- func (n *Net) ListenPacket(network string, address string) (net.PacketConn, error)
- func (n *Net) ListenUDP(network string, locAddr *net.UDPAddr) (UDPPacketConn, error)
- func (n *Net) ResolveUDPAddr(network, address string) (*net.UDPAddr, error)
- type NetConfig
- type Router
- type RouterConfig
- type UDPConn
- func (c *UDPConn) Close() error
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) Read(b []byte) (int, error)
- func (c *UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *UDPConn) RemoteAddr() net.Addr
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteDeadline(t time.Time) error
- func (c *UDPConn) Write(b []byte) (int, error)
- func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type UDPPacketConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk interface { SourceAddr() net.Addr DestinationAddr() net.Addr UserData() []byte Tag() string Clone() Chunk Network() string // returns "udp" or "tcp" String() string // contains filtered or unexported methods }
Chunk represents a packet passed around in the vnet
type ChunkFilter ¶
ChunkFilter is a handler users can add to filter chunks. If the filter returns false, the packet will be dropped.
type Dialer ¶
Dialer is identical to net.Dialer excepts that its methods (Dial, DialContext) are overridden to use virtual network. Use vnet.CreateDialer() to create an instance of this Dialer.
type EndpointDependencyType ¶
type EndpointDependencyType uint8
EndpointDependencyType defines a type of behavioral dependendency on the remote endpoint's IP address or port number. This is used for the two kinds of behaviors:
- Port mapping behavior
- Filtering behavior
See: https://tools.ietf.org/html/rfc4787
const ( // EndpointIndependent means the behavior is independent of the endpoint's address or port EndpointIndependent EndpointDependencyType = iota // EndpointAddrDependent means the behavior is dependent on the endpoint's address EndpointAddrDependent // EndpointAddrPortDependent means the behavior is dependent on the endpoint's address and port EndpointAddrPortDependent )
type Interface ¶
type Interface struct { InterfaceBase // contains filtered or unexported fields }
Interface ...
type NATMode ¶
type NATMode uint8
NATMode defines basic behavior of the NAT
const ( // NATModeNormal means the NAT behaves as a standard NAPT (RFC 2663). NATModeNormal NATMode = iota // NATModeNAT1To1 exhibits 1:1 DNAT where the external IP address is statically mapped to // a specific local IP address with port number is preserved always between them. // When this mode is selected, MappingBehavior, FilteringBehavior, PortPreservation and // MappingLifeTime of NATType are ignored. NATModeNAT1To1 )
type NATType ¶
type NATType struct { Mode NATMode MappingBehavior EndpointDependencyType FilteringBehavior EndpointDependencyType Hairpining bool // Not implemented yet PortPreservation bool // Not implemented yet MappingLifeTime time.Duration }
NATType has a set of parameters that define the behavior of NAT.
type NIC ¶
type NIC interface {
// contains filtered or unexported methods
}
NIC is a nework inerface controller that interfaces Router
type Net ¶
type Net struct {
// contains filtered or unexported fields
}
Net represents a local network stack euivalent to a set of layers from NIC up to the transport (UDP / TCP) layer.
func NewNet ¶
NewNet creates an instance of Net. If config is nil, the virtual network is disabled. (uses corresponding net.Xxxx() operations. By design, it always have lo0 and eth0 interfaces. The lo0 has the address 127.0.0.1 assigned by default. IP address for eth0 will be assigned when this Net is added to a router.
func (*Net) CreateDialer ¶
CreateDialer creates an instance of vnet.Dialer
func (*Net) InterfaceByName ¶
InterfaceByName returns the interface specified by name.
func (*Net) Interfaces ¶
Interfaces returns a list of the system's network interfaces.
func (*Net) ListenPacket ¶
ListenPacket announces on the local network address.
type NetConfig ¶
type NetConfig struct { // StaticIPs is an array of static IP addresses to be assigned for this Net. // If no static IP address is given, the router will automatically assign // an IP address. StaticIPs []string // StaticIP is deprecated. Use StaticIPs. StaticIP string }
NetConfig is a bag of configuration parameters passed to NewNet().
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router ...
func (*Router) AddChunkFilter ¶
func (r *Router) AddChunkFilter(filter ChunkFilter)
AddChunkFilter adds a filter for chunks traversing this router. You may add more than one filter. The filters are called in the order of this method call. If a chunk is dropped by a filter, subsequent filter will not receive the chunk.
func (*Router) AddHost ¶
AddHost adds a mapping of hostname and an IP address to the local resolver.
type RouterConfig ¶
type RouterConfig struct { // Name of router. If not specified, a unique name will be assigned. Name string // CIDR notation, like "192.0.2.0/24" CIDR string // StaticIPs is an array of static IP addresses to be assigned for this router. // If no static IP address is given, the router will automatically assign // an IP address. // This will be ignored if this router is the root. StaticIPs []string // StaticIP is deprecated. Use StaticIPs. StaticIP string // Internal queue size QueueSize int // Effective only when this router has a parent router NATType *NATType // Minimum Delay MinDelay time.Duration // Max Jitter MaxJitter time.Duration // Logger factory LoggerFactory logging.LoggerFactory }
RouterConfig ...
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. comatible with net.PacketConn and net.Conn
func (*UDPConn) Close ¶
Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
func (*UDPConn) Read ¶
Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*UDPConn) ReadFrom ¶
ReadFrom reads a packet from the connection, copying the payload into p. It returns the number of bytes copied into p and the return address that was on the packet. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Callers should always process the n > 0 bytes returned before considering the error err. ReadFrom can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*UDPConn) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*UDPConn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to ReadFrom or WriteTo. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.
A zero value for t means I/O operations will not time out.
func (*UDPConn) SetReadDeadline ¶
SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.
func (*UDPConn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.
func (*UDPConn) Write ¶
Write writes data to the connection. Write can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.