-
Notifications
You must be signed in to change notification settings - Fork 0
PeersControllCenter.go
DanielHauge edited this page Dec 18, 2017
·
1 revision
This file contains everything that controlls the peer to peer networking logic.
- Variables:
const PORT = ":2017"
var (
PeerIPs = make(map[string]string) /// Username:IP
Connections = make(map[string]net.Conn) /// Username:TCPConnection
Name string /// Username of this process (Node)
testing bool = true /// This users setting for testing
mutex = new(sync.Mutex) /// This users multiplexer
)- Methods:
func server()
- This function is for starting up a server (listens for incomming messages)
func introduceMyself(IP string)
- this is to connect to an existing peer to peer network.
func addPeer(msg Message)
- This is to tell everyone to a new node to the list of peers
func connectToPeers(msg Message)
- This one is to create connections to all peers that are registered. (for the new node)
func createConnection(IP string) (conn net.Conn)
- This is the function for making a connection to a specific IP, used for example by "connectToPeers" Function and other places.
func ReplyWithChain(user string)
- This is a function that will read the chain and reply with the chain to the node that requested it.
func disconnect(msg Message)
- This function is to tell everyone on the network it no longer wants to be in the network (We have not yet used it, but is there for future development)
func handleConnect(msg Message, conn net.Conn) bool
- This function is the center function for handling connection, it is used by an existing node in the network who needs to handle a new nodes wish to join the network.
- Then there is some help methods:
func alreadyAUser(user string) bool
- This method figures out if the user is allready a user in the network or not.
func getMyIP() string
- Quick and easy way to get IP
func getFromMap(mappa map[string]string) ([]string, []string)
- A way to get 2 string arrays out of a key value pair map.