Exemplo n.º 1
0
func MakePeerConn(encoder *gob.Encoder, peerId int, initiator bool) *PeerConn {
	pc := &PeerConn{
		sideband:   newShimConn(encoder, peerId),
		initiator:  initiator,
		udpConn:    nil,
		ignorePkts: true,
	}
	go func() {
		var err error
		pc.udpConn, err = nat.Connect(pc.sideband, pc.initiator)
		if err != nil {
			log.Println("err doing nat conn", err)
			// TODO REMOVE FROM MAP
		} else {
			log.Println("nat busted!")
			go func() {
				time.Sleep(2 * time.Second)
				pc.ignorePkts = false
				pc.udpConn.Write([]byte{0x00, 0x01, 0x02, 0x03})
			}()
			handleRemoteUdp(pc)
		}
	}()
	peerConnections[peerId] = pc
	return pc
}
Exemplo n.º 2
0
func main() {
	sideband, initiator, err := bouncer.Dial("http://natulte.net:4242/bounce/lolol")

	if err != nil {
		fmt.Println(err)
		return
	}

	conn, err := nat.Connect(sideband, initiator)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Got a nat-busted connection! %s to %s", conn.LocalAddr(), conn.RemoteAddr())
	conn.Close()
}