Documentation ¶
Overview ¶
Package lossyconn is a lossy connection simulator for Golang.
lossyconn provides packet oriented lossy connection for testing purpose
Index ¶
- type Address
- type ConnectionManager
- type LossyConn
- func (conn *LossyConn) Close() error
- func (conn *LossyConn) LocalAddr() net.Addr
- func (conn *LossyConn) Read(b []byte) (int, error)
- func (conn *LossyConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (conn *LossyConn) RemoteAddr() net.Addr
- func (conn *LossyConn) SetDeadline(t time.Time) error
- func (conn *LossyConn) SetDelayDeviation(deviation float64)
- func (conn *LossyConn) SetReadDeadline(t time.Time) error
- func (conn *LossyConn) SetWriteDeadline(t time.Time) error
- func (conn *LossyConn) String() string
- func (conn *LossyConn) Write(p []byte) (n int, err error)
- func (conn *LossyConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type Packet
- type TimedSender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address defines a simulated lossy conn address
func NewAddress ¶
func NewAddress() *Address
NewAddress creates a simulated address by filling with random numbers
type ConnectionManager ¶
type ConnectionManager struct {
// contains filtered or unexported fields
}
ConnectionManager contains all lossy connections
func NewConnectionManager ¶
func NewConnectionManager() *ConnectionManager
NewConnectionManager create a connection manager for all LossyConn
func (*ConnectionManager) Delete ¶
func (mgr *ConnectionManager) Delete(conn *LossyConn)
delete a connection from the pool
func (*ConnectionManager) Get ¶
func (mgr *ConnectionManager) Get(addr string) *LossyConn
return a connection from the pool
func (*ConnectionManager) Set ¶
func (mgr *ConnectionManager) Set(conn *LossyConn)
add a connection to the pool
type LossyConn ¶
type LossyConn struct {
// contains filtered or unexported fields
}
LossyConn implements a net.LossyConn with a given loss rate for sending
func NewLossyConn ¶
NewLossyConn create a loss connection with loss rate and latency
loss must be between [0,1]
delay is time in millisecond
func (*LossyConn) Close ¶
Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
func (*LossyConn) 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 (*LossyConn) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*LossyConn) 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 (*LossyConn) SetDelayDeviation ¶
SetDelayDeviation sets the deviation for delays, delay is the median value
Default : 1.0
func (*LossyConn) 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 (*LossyConn) 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.
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
Packet defines a data to be sent at some specific time
type TimedSender ¶
type TimedSender struct {
// contains filtered or unexported fields
}
TimedSender sends Packet to a connection at given time
func NewTimedSender ¶
func NewTimedSender() *TimedSender
func (*TimedSender) Len ¶
func (h *TimedSender) Len() int
func (*TimedSender) Less ¶
func (h *TimedSender) Less(i, j int) bool
func (*TimedSender) Pop ¶
func (h *TimedSender) Pop() interface{}
func (*TimedSender) Push ¶
func (h *TimedSender) Push(x interface{})
func (*TimedSender) Send ¶
func (h *TimedSender) Send(conn *LossyConn, packet Packet, delay time.Duration)
Send with a delay
func (*TimedSender) Swap ¶
func (h *TimedSender) Swap(i, j int)