<commit_before>// package swarm implements a connection muxer with a pair of channels
// to synchronize all network communication.
package swarm

import (
	"fmt"
	"io/ioutil"
	"sync"
	"time"

	peer "github.com/ipfs/go-libp2p-peer"
	transport "github.com/ipfs/go-libp2p-transport"
	metrics "github.com/ipfs/go-libp2p/p2p/metrics"
	mconn "github.com/ipfs/go-libp2p/p2p/metrics/conn"
	inet "github.com/ipfs/go-libp2p/p2p/net"
	conn "github.com/ipfs/go-libp2p/p2p/net/conn"
	filter "github.com/ipfs/go-libp2p/p2p/net/filter"
	addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
	logging "github.com/ipfs/go-log"
	ma "github.com/jbenet/go-multiaddr"
	ps "github.com/jbenet/go-peerstream"
	pst "github.com/jbenet/go-stream-muxer"
	psmss "github.com/jbenet/go-stream-muxer/multistream"
	spdy "github.com/jbenet/go-stream-muxer/spdystream"
	yamux "github.com/jbenet/go-stream-muxer/yamux"
	"github.com/jbenet/goprocess"
	goprocessctx "github.com/jbenet/goprocess/context"
	mafilter "github.com/whyrusleeping/multiaddr-filter"
	context "golang.org/x/net/context"
)

var log = logging.Logger("swarm2")

var PSTransport pst.Transport

func init() {
	msstpt := psmss.NewBlankTransport()

	ymxtpt := &yamux.Transport{
		AcceptBacklog:          8192,
		ConnectionWriteTimeout: time.Second * 10,
		KeepAliveInterval:      time.Second * 30,
		EnableKeepAlive:        true,
		MaxStreamWindowSize:    uint32(1024 * 256),
		LogOutput:              ioutil.Discard,
	}

	msstpt.AddTransport("/yamux/1.0.0", ymxtpt)
	msstpt.AddTransport("/spdy/3.1.0", spdy.Transport)

	PSTransport = msstpt
}

// Swarm is a connection muxer, allowing connections to other peers to
// be opened and closed, while still using the same Chan for all
// communication. The Chan sends/receives Messages, which note the
// destination or source Peer.
//
// Uses peerstream.Swarm
type Swarm struct {
	swarm *ps.Swarm
	local peer.ID
	peers peer.Peerstore
	connh ConnHandler
<commit_msg>add env var for overriding muxer prefs<commit_after>// package swarm implements a connection muxer with a pair of channels
// to synchronize all network communication.
package swarm

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"sync"
	"time"

	peer "github.com/ipfs/go-libp2p-peer"
	transport "github.com/ipfs/go-libp2p-transport"
	metrics "github.com/ipfs/go-libp2p/p2p/metrics"
	mconn "github.com/ipfs/go-libp2p/p2p/metrics/conn"
	inet "github.com/ipfs/go-libp2p/p2p/net"
	conn "github.com/ipfs/go-libp2p/p2p/net/conn"
	filter "github.com/ipfs/go-libp2p/p2p/net/filter"
	addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
	logging "github.com/ipfs/go-log"
	ma "github.com/jbenet/go-multiaddr"
	ps "github.com/jbenet/go-peerstream"
	pst "github.com/jbenet/go-stream-muxer"
	psmss "github.com/jbenet/go-stream-muxer/multistream"
	spdy "github.com/jbenet/go-stream-muxer/spdystream"
	yamux "github.com/jbenet/go-stream-muxer/yamux"
	"github.com/jbenet/goprocess"
	goprocessctx "github.com/jbenet/goprocess/context"
	mafilter "github.com/whyrusleeping/multiaddr-filter"
	context "golang.org/x/net/context"
)

var log = logging.Logger("swarm2")

var PSTransport pst.Transport

func init() {
	msstpt := psmss.NewBlankTransport()

	ymxtpt := &yamux.Transport{
		AcceptBacklog:          8192,
		ConnectionWriteTimeout: time.Second * 10,
		KeepAliveInterval:      time.Second * 30,
		EnableKeepAlive:        true,
		MaxStreamWindowSize:    uint32(1024 * 256),
		LogOutput:              ioutil.Discard,
	}

	msstpt.AddTransport("/yamux/1.0.0", ymxtpt)
	msstpt.AddTransport("/spdy/3.1.0", spdy.Transport)

	// allow overriding of muxer preferences
	if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
		msstpt.OrderPreference = strings.Fields(prefs)
	}

	PSTransport = msstpt
}

// Swarm is a connection muxer, allowing connections to other peers to
// be opened and closed, while still using the same Chan for all
// communication. The Chan sends/receives Messages, which note the
// destination or source Peer.
//
// Uses peerstream.Swarm
type Swarm struct {
	swarm *ps.Swarm
	local peer.ID
	peers peer.Peerstore
	connh ConnHandler

{'fraction_non_alphanumeric': 0.12668463611859837, 'fraction_numerical': 0.018867924528301886, 'mean_word_length': 3.894484412470024, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4295821', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1616, 'n_words': 303}