ceremonyclient/go-libp2p/p2p/net/pnet/protector.go

19 lines
355 B
Go
Raw Permalink Normal View History

2023-08-21 03:50:38 +00:00
package pnet
import (
"errors"
"net"
ipnet "github.com/libp2p/go-libp2p/core/pnet"
)
// NewProtectedConn creates a new protected connection
func NewProtectedConn(psk ipnet.PSK, conn net.Conn) (net.Conn, error) {
if len(psk) != 32 {
return nil, errors.New("expected 32 byte PSK")
}
var p [32]byte
copy(p[:], psk)
return newPSKConn(&p, conn)
}