<commit_before>package main

import (
	"context"
	"crypto/tls"
	"log"

	nnet "github.com/nimona/go-nimona/net"
	prot "github.com/nimona/go-nimona/net/protocol"
)

func main() {
	peerA, err := newPeer("PeerA")
	if err != nil {
		log.Fatal("Could not create peer A", err)
	}

	peerB, err := newPeer("PeerB")
	if err != nil {
		log.Fatal("Could not create peer B", err)
	}

	peerC, err := newPeer("PeerC")
	if err != nil {
		log.Fatal("Could not create peer C", err)
	}

	log.Println("Peer A address:", peerA.GetAddresses())

	for _, addr := range peerA.GetAddresses() {
		endpoint := addr + "/tls/yamux/router/relay:keepalive"
		log.Println("-------- Dialing", endpoint)
		if _, _, err := peerB.DialContext(context.Background(), endpoint); err != nil {
			log.Println("Dial error", err)
		}

		// endpoint = addr + "/tls/yamux/router/ping"
		// time.Sleep(5 * time.Second)
		// log.Println("-------- SECOND Dial", endpoint)
		// if err := peerB.DialContext(context.Background(), endpoint); err != nil {
		// 	log.Println("Dial error", err)
		// }

		addrPeerB := peerB.GetAddresses()[0]
		endpoint = addrPeerB + "/tls/yamux/router/relay:" + addr + "/tls/yamux/router/ping"
		log.Println("-------- THIRD Dial", endpoint)
		if _, _, err := peerC.DialContext(context.Background(), endpoint); err != nil {
			log.Println("Dial error", err)
		}
	}
}

func newPeer(peerID string) (nnet.Net, error) {
	ctx := context.Background()
	crt, err := GenX509KeyPair()
	if err != nil {
		return nil, err
	}

	yamux := prot.NewYamux()
	router := prot.NewRouter()
	identity := &prot.IdentityProtocol{Local: peerID}
	tls := &prot.SecProtocol{
		Config: tls.Config{
			Certificates:       []tls.Certificate{crt},
			InsecureSkipVerify: true,
		},
	}
	ping := &Ping{}

	tcp := nnet.NewTransportTCP("0.0.0.0", 0)
	// ws := nnet.NewTransportWebsocket("0.0.0.0", 0)

	nn := nnet.New(ctx)
	relay := prot.NewRelayProtocol(nn)
	nn.AddTransport(yamux, router)
	nn.AddTransport(tcp, tls, yamux, router)
	// nn.AddTransport(ws, []nnet.Protocol{tls, yamux, router})
	nn.AddProtocols(router, tls, yamux, identity, ping, relay)
	router.AddRoute(relay)
	router.AddRoute(ping)
	router.AddRoute(identity, ping)
	return nn, nil
}<commit_msg>Fix example<commit_after>package main

import (
	"context"
	"crypto/tls"
	"log"

	nnet "github.com/nimona/go-nimona/net"
	prot "github.com/nimona/go-nimona/net/protocol"
)

func main() {
	peerA, err := newPeer("PeerA")
	if err != nil {
		log.Fatal("Could not create peer A", err)
	}

	peerB, err := newPeer("PeerB")
	if err != nil {
		log.Fatal("Could not create peer B", err)
	}

	peerC, err := newPeer("PeerC")
	if err != nil {
		log.Fatal("Could not create peer C", err)
	}

	log.Println("Peer A address:", peerA.GetAddresses())

	for _, addr := range peerA.GetAddresses() {
		endpoint := addr + "/tls/yamux/router/relay:keepalive"
		log.Println("-------- Dialing", endpoint)
		if _, _, err := peerB.DialContext(context.Background(), endpoint); err != nil {
			log.Println("Dial error", err)
		}

		// endpoint = addr + "/tls/yamux/router/ping"
		// time.Sleep(5 * time.Second)
		// log.Println("-------- SECOND Dial", endpoint)
		// if err := peerB.DialContext(context.Background(), endpoint); err != nil {
		// 	log.Println("Dial error", err)
		// }

		addrPeerB := peerB.GetAddresses()[0]
		endpoint = addrPeerB + "/tls/yamux/router/relay:" + addr + "/tls/yamux/router/ping"
		log.Println("-------- THIRD Dial", endpoint)
		if _, _, err := peerC.DialContext(context.Background(), endpoint); err != nil {
			log.Println("Dial error", err)
		}
	}
}

func newPeer(peerID string) (nnet.Net, error) {
	ctx := context.Background()
	crt, err := GenX509KeyPair()
	if err != nil {
		return nil, err
	}

	yamux := prot.NewYamux()
	router := prot.NewRouter()
	identity := &prot.IdentityProtocol{Local: peerID}
	tls := &prot.SecProtocol{
		Config: tls.Config{
			Certificates:       []tls.Certificate{crt},
			InsecureSkipVerify: true,
		},
	}
	ping := &Ping{}

	tcp := nnet.NewTransportTCP("0.0.0.0", 0)
	// ws := nnet.NewTransportWebsocket("0.0.0.0", 0)

	nn := nnet.New(ctx)
	relay := prot.NewRelayProtocol(nn, []string{})
	nn.AddTransport(yamux, router)
	nn.AddTransport(tcp, tls, yamux, router)
	// nn.AddTransport(ws, []nnet.Protocol{tls, yamux, router})
	nn.AddProtocols(router, tls, yamux, identity, ping, relay)
	router.AddRoute(relay)
	router.AddRoute(ping)
	router.AddRoute(identity, ping)
	return nn, nil
}
{'fraction_non_alphanumeric': 0.18509288627095605, 'fraction_numerical': 0.006796556411418215, 'mean_word_length': 3.6424815983175605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5292638', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1677, 'n_words': 352}