Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tea.melonie54.xyz/melonie/snowball

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tea.melonie54.xyz/melonie/snowball

  • v0.0.0-20220302222227-0347aa6bde01
  • Go
  • Socket score

Version published
Created
Source

Snowball

Small communication protocol for TCP connections

Example client:

wg := &sync.WaitGroup{}

// Resolve TCP address
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:12345")
if err != nil {
	t.Fatal(err)
}

// Create snowball client
var snow *SnowballClient
snow = NewSnowballClient(wg, 3, tcpAddr, func(packet *packet.SnowballPacket) {
	// Packet receiving logic only packets with `toAddr = 3` will be handled here
	// Packets with `toAddr = 2` are forwarded to all clients from the server but
	// the `toAddr` is changed to match to receiving client ID
	switch packet.Id {
	case 2: 
		// `MakeReply` can be used to create a packet to send back to the return address 
		snow.Send(packet.MakeReply(3, packet.Data))
	}
})

// A WaitGroup can be used to prevent the program from closing
wg.Wait()

// Create and send a packet (with ID: 2) to client (with ID: 4)
// The from address is set to the current client
// A binary packet can be generated using a byte buffer and the functions in `net-byte-utils.go`
buf := new(bytes.Buffer)
utils.WriteString(buf, "hello")
snow.Send(NewSnowballPacketFromBytes(2, 0, 4, buf.Bytes()))

Example server:

wg := &sync.WaitGroup{}

tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:12346")
if err != nil {
	t.Fatal(err)
}

var snow *SnowballServer
snow = NewSnowballServer(wg, tcpAddr, func(packet *packet.SnowballPacket) {
	// Packet receiving logic only packets with `toAddr = 1` will be handled here
	// Packets with other addresses are automatically routed to the client
	// Packets with `toAddr = 2` are forwarded to all clients automatically
	switch packet.Id {
	case 2: 
		// `MakeReply` can be used to create a packet to send back to the return address 
		snow.Send(packet.MakeReply(3, packet.Data))
	}
})
if err != nil {
	t.Fatal(err)
}
// `Serve` is non-blocking
snow.Serve()

// A WaitGroup can be used to prevent the program from closing
wg.Wait()

Packet IDs:

  • 0x00 - Reserved for the unknown packet
  • 0x01 - Reserved for the Hello packet

Client IDs:

  • 0x00 - Reserved for the unknown client (if used as fromAddr it is changed to the current client ID before sending)
  • 0x01 - Reserved for the server
  • 0x02 - Reserved for sending packets to all clients (can be used from the client or server Send methods)

FAQs

Package last updated on 02 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc