go-stun icon indicating copy to clipboard operation
go-stun copied to clipboard

Go implementation of STUN, TURN and ICE Protocols

go-stun

Go implementation of STUN, TURN and ICE Protocols

Build Status Coverage Status Go Report Card GoDoc

Features

  • [x] STUN Encoder/Decoder
  • [x] STUN Client/Server
  • [x] STUN Authorization
  • [x] STUN Transactions
  • [x] STUN Multiplexing
  • [ ] STUN Redirection
  • [ ] NAT Behavior Discovery
  • [x] ICE Messages
  • [ ] ICE Agent
  • [ ] ICE Gathering
  • [ ] ICE Lite
  • [x] TURN Messages
  • [x] TURN Client
  • [ ] TURN Server
  • [ ] ...

Installation

go get github.com/pixelbender/go-stun/...

STUN: Server reflexive transport address discovery

package main

import (
	"github.com/pixelbender/go-stun/stun"
	"fmt"
)

func main() {
    conn, addr, err := stun.Discover("stun:stun.l.google.com:19302")
	if err != nil {
    	fmt.Println(err)
    	return
    }
    defer conn.Close()
	fmt.Printf("Local address: %v, Server reflexive address: %v", conn.LocalAddr(), addr)
}

TURN: Relayed transport address allocation

package main

import (
	"github.com/pixelbender/go-stun/turn"
	"fmt"
)

func main() {
	conn, err := turn.Allocate("turn:username:[email protected]")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer conn.Close()
	fmt.Printf("Local address: %v, Relayed transport address: %v", conn.LocalAddr(), conn.RelayedAddr())
}

Specifications