All Projects → cevatbarisyilmaz → Lossy

cevatbarisyilmaz / Lossy

Licence: mit
Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Lossy

black-hat-python3-code
🏴‍☠️ tools (py3 version) of Black Hat Python book 🏴‍☠️
Stars: ✭ 51 (-81.59%)
Mutual labels:  udp
webcam
OpenCV and UDP webcam streaming
Stars: ✭ 43 (-84.48%)
Mutual labels:  udp
Hsweb Iot Cloud
本项目已迁移至 github.com/jetlinks
Stars: ✭ 258 (-6.86%)
Mutual labels:  udp
riemannx
A riemann client for elixir (TCP/UDP/TLS supported)
Stars: ✭ 23 (-91.7%)
Mutual labels:  udp
udpeer
A simple UDP peer to peer networking proxy using webrtc
Stars: ✭ 19 (-93.14%)
Mutual labels:  udp
STUP-Protocol
Secure/Speedup TCP-like UDP protocol
Stars: ✭ 12 (-95.67%)
Mutual labels:  udp
ENetUnityMobile
Using ENet-CSharp for a multiplayer setup with a Unity Client and .Net Core Server environment
Stars: ✭ 27 (-90.25%)
Mutual labels:  udp
Valvesockets Csharp
Managed C# abstraction of GameNetworkingSockets library by Valve Software
Stars: ✭ 273 (-1.44%)
Mutual labels:  udp
game 01
Scalable MMORPG game server based on entity control
Stars: ✭ 19 (-93.14%)
Mutual labels:  udp
ethereum-dissectors
🔍Wireshark dissectors for Ethereum devp2p protocols
Stars: ✭ 82 (-70.4%)
Mutual labels:  udp
rmnp
Realtime Multiplayer Networking Protocol
Stars: ✭ 41 (-85.2%)
Mutual labels:  udp
m2o-reborn
Original Mafia2 Multiplayer modification
Stars: ✭ 31 (-88.81%)
Mutual labels:  udp
EdgeAdmin
CDN & WAF集群管理系统。
Stars: ✭ 199 (-28.16%)
Mutual labels:  udp
ddos
Simple dos attack utility
Stars: ✭ 36 (-87%)
Mutual labels:  udp
Lunamultiplayer
Multiplayer mod for Kerbal Space Program (KSP)
Stars: ✭ 265 (-4.33%)
Mutual labels:  udp
udpt
UDP Transport: compress, encrypt and send any data reliably over unreliable UDP connections
Stars: ✭ 40 (-85.56%)
Mutual labels:  udp
dtls
Datagram Transport Layer Security (DTLS) client.
Stars: ✭ 72 (-74.01%)
Mutual labels:  udp
Kcp Go
A Crypto-Secure, Production-Grade Reliable-UDP Library for golang with FEC
Stars: ✭ 3,177 (+1046.93%)
Mutual labels:  udp
Wireguard Docs
📖 Unofficial WireGuard Documentation: Setup, Usage, Configuration, and full example setups for VPNs supporting both servers & roaming clients.
Stars: ✭ 3,201 (+1055.6%)
Mutual labels:  udp
http-connection-lifecycle
Complete and detailed explanation of HTTP connection lifecycle
Stars: ✭ 43 (-84.48%)
Mutual labels:  udp

lossy

GoDoc GitHub release (latest SemVer) GitHub Go Report Card

Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces.

Its main usage is to test robustness of applications and network protocols run over unreliable transport protocols such as UDP or IP. As a side benefit, it can also be used as outbound bandwidth limiter.

lossy only alters the writing side of the connection, reading side is kept as it is.

Example

package main

import (
	"fmt"
	"github.com/cevatbarisyilmaz/lossy"
	"log"
	"math/rand"
	"net"
	"time"
)

const packetSize = 64

func main() {
	// Create two connection endpoints over UDP
	packetConn, conn := createConnections()

	// Create a lossy packet connection
	bandwidth := 1048 // 8 Kbit/s
	minLatency := 100 * time.Millisecond
	maxLatency := time.Second
	packetLossRate := 0.33
	headerOverhead := lossy.UDPv4MinHeaderOverhead
	lossyPacketConn := lossy.NewPacketConn(packetConn, bandwidth, minLatency, maxLatency, packetLossRate, headerOverhead)

	// Write some packets via lossy
	var bytesWritten int
	const packetCount = 32
	go func() {
		for i := 0; i < packetCount; i++ {
			packet := createPacket()
			_, err := lossyPacketConn.WriteTo(packet, conn.LocalAddr())
			if err != nil {
				log.Fatal(err)
			}
			bytesWritten += len(packet) + headerOverhead
		}
		fmt.Println("Sent", packetCount, "packets with total size of", bytesWritten, "bytes")
		baseTransmissionDuration := time.Duration(float64(bytesWritten * int(time.Second)) / float64(bandwidth))
		earliestCompletion := baseTransmissionDuration + minLatency
		latestCompletion := baseTransmissionDuration + maxLatency
		fmt.Println("Expected transmission duration is between", earliestCompletion, "and", latestCompletion)
	}()

	// Read packets at the other side
	const timeout = 3 * time.Second
	var packets, bytesRead int
	startTime := time.Now()
	for {
		_ = conn.SetReadDeadline(time.Now().Add(timeout))
		buffer := make([]byte, packetSize)
		n, err := conn.Read(buffer)
		if err != nil {
			break
		}
		bytesRead += n + headerOverhead
		packets++
	}
	dur := time.Now().Sub(startTime) - timeout
	fmt.Println("Received", packets, "packets with total size of", bytesRead, "bytes in", dur)

	// Close the connections
	_ = lossyPacketConn.Close()
	_ = conn.Close()
}

func createConnections() (net.PacketConn, net.Conn) {
	packetConn, err := net.ListenUDP("udp", &net.UDPAddr{
		IP:   net.IPv4(127, 0, 0, 1),
		Port: 0,
	})
	if err != nil {
		log.Fatal(err)
	}
	conn, err := net.DialUDP("udp", nil, packetConn.LocalAddr().(*net.UDPAddr))
	if err != nil {
		log.Fatal(err)
	}
	return packetConn, conn
}

func createPacket() []byte {
	packet := make([]byte, packetSize)
	rand.Read(packet)
	return packet
}

Output

Sent 32 packets with total size of 2944 bytes
Expected transmission duration is between 2.909160305s and 3.809160305s
Received 23 packets with total size of 2116 bytes in 3.2507523s
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].