Documentation ¶
Index ¶
- Variables
- func Debugf(format string, args ...interface{})
- func DecodeRSAPublicKey(encodedKey string) *rsa.PublicKey
- func DecryptWithPrivateKey(ciphertext []byte, privateKey *rsa.PrivateKey) []byte
- func EncodeRSAPublicKey(pub *rsa.PublicKey) string
- func EncryptWithPublicKey(plaintext []byte, publicKey *rsa.PublicKey) []byte
- func ExtraDebugf(format string, args ...interface{})
- func GenerateSecretPhrase() []byte
- func KeyShortName(key []byte) string
- func NodeShortName(node *Node) string
- func PublicKeyToId(publicKey *rsa.PublicKey) string
- func ShortName(node string) string
- func VerifySignature(msg []byte, sign []byte, publicKey *rsa.PublicKey) bool
- type Announcement
- type Config
- type Message
- type Network
- func (p2pnet *Network) AddEdge(nodeId string, peers []string)
- func (p2pnet *Network) AddEndpoint(endpoint string)
- func (p2pnet *Network) Announce(myNodeName string, myBindport string)
- func (p2pnet *Network) Broadcast(ty string, payload []byte) string
- func (p2pnet *Network) Connect(addr string) error
- func (p2pnet *Network) ConnectNewEndpointsLoop()
- func (p2pnet *Network) Listen()
- func (p2pnet *Network) LoadDefaultConfig(name string)
- func (p2pnet *Network) SaveDefaultConfig(name string)
- func (p2pnet *Network) SendMessage(msg *Message) string
- func (p2pnet *Network) ServicesList() []ServiceAnnouncement
- func (p2pnet *Network) Start()
- type Node
- type SearchResult
- type ServiceAnnouncement
Constants ¶
This section is empty.
Variables ¶
View Source
var ExtraDebug bool = false
View Source
var GlobalDebug bool = false
View Source
var GlobalVerbose bool = false
Functions ¶
func DecodeRSAPublicKey ¶
func DecryptWithPrivateKey ¶
func DecryptWithPrivateKey(ciphertext []byte, privateKey *rsa.PrivateKey) []byte
func EncodeRSAPublicKey ¶
func EncryptWithPublicKey ¶
func ExtraDebugf ¶
func ExtraDebugf(format string, args ...interface{})
func GenerateSecretPhrase ¶
func GenerateSecretPhrase() []byte
func KeyShortName ¶
func NodeShortName ¶
func PublicKeyToId ¶
Types ¶
type Announcement ¶
type Network ¶
type Network struct { NodeName string // Display name of the node BindAddrPort string // Address and port to listen on ConnectedNodes *sync.Map // Map of connected nodes i.e. neighbours PrivateKey *rsa.PrivateKey //This node's private key PublicKey *rsa.PublicKey //This node's public key MsgCallbacks *sync.Map //Map of message types to callback functions Id string //Id of this node, usually the public key Nodes *sync.Map //All nodes that have been seen SeenMessages *sync.Map //All message ids that have been seen, to prevent duplicates MessageCounter int //Number of messages sent DuplicateCounter int //Number of duplicate messages seen and dropped ForwardCounter int //Number of messages forwarded ReceivedCounter int //Number of messages received PossibleEndpoints *sync.Map //All possible endpoints (ip:port) that have been seen AnnounceInterval int //How often to announce this node's existence on the network AutoPort bool //Whether to automatically increment the listening port number if the desired port is in use Services *sync.Map //A collection of the currentknown services, as gathered from service announcements on the network MessageIdCallbacks *sync.Map //Handlers for message replies. P2p works asynchronously, so every request has a callback id, and the reply contains that id Topology *sync.Map //The current network topology, as gathered from topology announcements on the network Version int //The version of the p2p protocol MaxHops int //The maximum number of hops a message can take before being dropped TrustedKeys []string //List of trusted keys ConfigBaseDir string //The base directory for config files. Leave unset for default(home directory/.p2p) }
func NewNetwork ¶
func (*Network) AddEndpoint ¶
func (*Network) Broadcast ¶
Broadcasts bytes to all nodes. The bytes are not examined or encrypted in any way
func (*Network) ConnectNewEndpointsLoop ¶
func (p2pnet *Network) ConnectNewEndpointsLoop()
func (*Network) LoadDefaultConfig ¶
func (*Network) SaveDefaultConfig ¶
func (*Network) SendMessage ¶
Send a message to a node, encrypting it with their public key, and routing it through the network
func (*Network) ServicesList ¶
func (p2pnet *Network) ServicesList() []ServiceAnnouncement
type Node ¶
type Node struct { Conn net.Conn `json:"-"` PublicKey *rsa.PublicKey AESKey [32]byte SymmetricKeyReceive []byte `json:"-"` SymmetricKeySend []byte `json:"-"` Buff bufio.Reader `json:"-"` SeenIds *sync.Map //Attached to nodes(and thus connections, so we can route backwards) LastSeen time.Time SendMutex sync.Mutex //Mutex for sending messages }
func (*Node) DisplayName ¶
func (*Node) PublicKeyString ¶
type SearchResult ¶
Click to show internal directories.
Click to hide internal directories.