<commit_before>package relay

import (
	"encoding/binary"
	"errors"
	"io"

	pb "github.com/libp2p/go-libp2p-circuit/pb"

	ggio "github.com/gogo/protobuf/io"
	proto "github.com/gogo/protobuf/proto"
	peer "github.com/libp2p/go-libp2p-peer"
	pstore "github.com/libp2p/go-libp2p-peerstore"
	ma "github.com/multiformats/go-multiaddr"
	mh "github.com/multiformats/go-multihash"
)

func peerToPeerInfo(p *pb.CircuitRelay_Peer) (pstore.PeerInfo, error) {
	if p == nil {
		return pstore.PeerInfo{}, errors.New("nil peer")
	}

	h, err := mh.Cast(p.Id)
	if err != nil {
		return pstore.PeerInfo{}, err
	}

	addrs := make([]ma.Multiaddr, len(p.Addrs))
	for i := 0; i < len(addrs); i++ {
		a, err := ma.NewMultiaddrBytes(p.Addrs[i])
		if err != nil {
			return pstore.PeerInfo{}, err
		}
		addrs[i] = a
	}

	return pstore.PeerInfo{ID: peer.ID(h), Addrs: addrs}, nil
}

func peerInfoToPeer(pi pstore.PeerInfo) *pb.CircuitRelay_Peer {
	addrs := make([][]byte, len(pi.Addrs))
	for i := 0; i < len(addrs); i++ {
		addrs[i] = pi.Addrs[i].Bytes()
	}

	p := new(pb.CircuitRelay_Peer)
	p.Id = []byte(pi.ID)
	p.Addrs = addrs

	return p<commit_msg>fix: dont error out on unknown addrs in peer info<commit_after>package relay

import (
	"encoding/binary"
	"errors"
	"io"

	pb "github.com/libp2p/go-libp2p-circuit/pb"

	ggio "github.com/gogo/protobuf/io"
	proto "github.com/gogo/protobuf/proto"
	peer "github.com/libp2p/go-libp2p-peer"
	pstore "github.com/libp2p/go-libp2p-peerstore"
	ma "github.com/multiformats/go-multiaddr"
	mh "github.com/multiformats/go-multihash"
)

func peerToPeerInfo(p *pb.CircuitRelay_Peer) (pstore.PeerInfo, error) {
	if p == nil {
		return pstore.PeerInfo{}, errors.New("nil peer")
	}

	h, err := mh.Cast(p.Id)
	if err != nil {
		return pstore.PeerInfo{}, err
	}

	addrs := make([]ma.Multiaddr, len(p.Addrs))
	for i := 0; i < len(addrs); i++ {
		a, err := ma.NewMultiaddrBytes(p.Addrs[i])
		if err != nil {
			addrs[i] = a
		}
	}

	return pstore.PeerInfo{ID: peer.ID(h), Addrs: addrs}, nil
}

func peerInfoToPeer(pi pstore.PeerInfo) *pb.CircuitRelay_Peer {
	addrs := make([][]byte, len(pi.Addrs))
	for i := 0; i < len(addrs); i++ {
		addrs[i] = pi.Addrs[i].Bytes()
	}

	p := new(pb.CircuitRelay_Peer)
	p.Id = []byte(pi.ID)
	p.Addrs = addrs

	return p
{'fraction_non_alphanumeric': 0.17613132209405502, 'fraction_numerical': 0.00709849157054126, 'mean_word_length': 3.880952380952381, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '670154', 'n_tokens_mistral': 1033, 'n_tokens_neox': 987, 'n_words': 185}