private void InsertNewPeer(Socket newConnection) { //crea un nuovo peer con un socket giĆ collegato e una nuova connessione con questo peer, e la inserisce nel contenitore mConnections CPeer newPeer = CPeer.CreatePeer(Convert.ToString((newConnection.RemoteEndPoint as IPEndPoint).Address), (newConnection.RemoteEndPoint as IPEndPoint).Port, newConnection); mPeers.Insert(newPeer, true); }
static void Main(string[] args) { //Apre il canale di comunicazione per GUI https://github.com/Kojee/BlockChainGUI OpenWCFServices(); //List<CPeer> lp = GenPeersList(); List <CPeer> lp = new List <CPeer>(); CIO.WriteLine("Enter the peer address:"); string firstPeerIP = Console.ReadLine(); try { if (!IPAddress.TryParse(firstPeerIP, out var IP)) { firstPeerIP = "192.168.1.1"; } } catch { firstPeerIP = "192.168.1.1"; } lp.Add(CPeer.CreatePeer(firstPeerIP, 4000)); CServer.Instance.InitializePeersList(lp); Services cmd = new Services(); bool b = true; while (b) { string command = Console.ReadLine().ToLower(); switch (command) { case "transaction": { CIO.WriteLine("Enter destination address:"); string hashReceiver = Console.ReadLine(); CIO.WriteLine("Enter the amout of coins to send:"); double amount = Convert.ToDouble(Console.ReadLine()); Transaction tx = new Transaction(amount, hashReceiver, CServer.rsaKeyPair); break; } case "miner": { CServer.Instance.StartMining(); break; } case "sync": { CServer.Instance.SyncBlockchain(); break; } case "address": { CIO.WriteLine(cmd.GetKeystore()); break; } case "balance": { CIO.WriteLine(cmd.GetBalance().ToString()); break; } case "stop": { b = false; Environment.Exit(1); break; } default: { CIO.WriteLine("Invalid command."); break; } } } }
public static CPeer Deserialize(string Peer) { string[] peerField = Peer.Split(','); return(CPeer.CreatePeer(peerField[0], Convert.ToInt32(peerField[1]))); }