net

package
v0.0.0-...-c57a2f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2019 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The version of the encryption algorithm used. Currently only 1 is supported
	CiphertextVersion = 1

	// Length of the serialized version in bytes
	CiphertextVersionBytes = 4

	// Length of the secret key used to generate the AES and MAC keys in bytes
	SecretKeyBytes = 32

	// Length of the AES key in bytes
	AESKeyBytes = 32

	// Length of the MAC key in bytes
	MacKeyBytes = 32

	// Length of the RSA encrypted secret key ciphertext in bytes
	EncryptedSecretKeyBytes = 512

	// Length of the MAC in bytes
	MacBytes = 32

	// Length of nacl nonce
	NonceBytes = 24

	// Length of nacl ephemeral public key
	EphemeralPublicKeyBytes = 32
)

Variables

View Source
var (
	// The ciphertext cannot be shorter than CiphertextVersionBytes + EncryptedSecretKeyBytes + aes.BlockSize + MacKeyBytes
	ErrShortCiphertext = errors.New("Ciphertext is too short")

	// The HMAC included in the ciphertext is invalid
	ErrInvalidHmac = errors.New("Invalid Hmac")

	// Nacl box decryption failed
	BoxDecryptionError = errors.New("Failed to decrypt curve25519")

	// Satic salt used in the hdkf
	Salt = []byte("EvenNetwork Encryption Algorithm")
)
View Source
var (
	OutOfOrderMessage error = errors.New("Message arrived out of order")
	DuplicateMessage  error = errors.New("Duplicate Message")
)
View Source
var STUN_PORT int = 3478
View Source
var STUN_SERVERS []string = []string{
	"stun.ekiga.net",
	"stun.ideasip.com",
	"stun.voiparound.com",
	"stun.voipbuster.com",
	"stun.voipstunt.com",
	"stun.voxgratia.org",
}

Functions

func CreateHiddenServiceKey

func CreateHiddenServiceKey(repoPath string) (onionAddr string, err error)

Generate a new RSA key and onion address and save it to the repo

func Decrypt

func Decrypt(privKey libp2p.PrivKey, ciphertext []byte) ([]byte, error)

func Encrypt

func Encrypt(pubKey libp2p.PubKey, plaintext []byte) ([]byte, error)

func GetTorControlPort

func GetTorControlPort() (int, error)

Return the Tor control port if Tor is running or an error

func MaybeCreateHiddenServiceKey

func MaybeCreateHiddenServiceKey(repoPath string) (onionAddr string, err error)

Generate a new key pair if one does not already exist

func NATtoString

func NATtoString(i stunlib.NATType) string

func Shuffle

func Shuffle(a []string)

func Stun

func Stun() (int, error)

Types

type BanManager

type BanManager struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

func NewBanManager

func NewBanManager(blockedIds []peer.ID) *BanManager

func (*BanManager) AddBlockedId

func (bm *BanManager) AddBlockedId(peerId peer.ID)

func (*BanManager) GetBlockedIds

func (bm *BanManager) GetBlockedIds() []peer.ID

func (*BanManager) IsBanned

func (bm *BanManager) IsBanned(peerId peer.ID) bool

func (*BanManager) RemoveBlockedId

func (bm *BanManager) RemoveBlockedId(peerId peer.ID)

func (*BanManager) SetBlockedIds

func (bm *BanManager) SetBlockedIds(peerIds []peer.ID)

type NetworkService

type NetworkService interface {
	// Handle incoming streams
	HandleNewStream(s inet.Stream)

	// Get handler for message type
	HandlerForMsgType(t pb.Message_MessageType) func(peer.ID, *pb.Message, interface{}) (*pb.Message, error)

	// Send request to a peer and wait for the response
	SendRequest(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error)

	// Send a message to a peer without requiring a response
	SendMessage(ctx context.Context, p peer.ID, pmes *pb.Message) error

	// Disconnect from the given peer
	DisconnectFromPeer(p peer.ID) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL