Exemple #1
0
        public MainWindow()
        {
            InitializeComponent();
            //bankClient = new RestClient(bankUrl);
            //minerClient = new RestClient(minerUrl);
            //existUsers = new Dictionary<int, uint>();
            sendJobs         = new List <string[]>();
            clientJobResults = new List <string[]>();
            currJobsLogged   = new List <string[]>();

            url     = "https://localhost:44370/";
            webPool = new RestClient(url);

            //create current client connection, AKA this block is the server thread
            currClient      = new ClientDataStruct();
            currClient.ip   = "localhost";
            currClient.port = (new Random().Next(6000, 9999)).ToString("D4");//random generation of port number
            ourServ         = new PeerProgram();
            currClient.port = ourServ.CreateServer(currClient.ip, currClient.port);
            ourRemoteThread = ConnectToRemote(currClient.ip, currClient.port);

            JoinPool();
            ourBlockchain = ourRemoteThread.GetCurrentChain();

            ourAddrText.Text = "Your Client Address is " + currClient.ip + ":" + currClient.port;
            MinerThread();
        }
Exemple #2
0
        private void JoinPool()//join pool via web service
        {
            RestRequest req = new RestRequest("api/Client/AddClient");

            encodeClient      = new ClientDataStruct();
            encodeClient.ip   = EncodeTo64(currClient.ip);
            encodeClient.port = EncodeTo64(currClient.port);
            req.AddJsonBody(encodeClient);
            webPool.Post(req);
        }
Exemple #3
0
        /*
         * Algo to shuffle list to create fairness for peer connection
         * Reference: https://www.dotnetperls.com/fisher-yates-shuffle
         */
        private void ShuffleList()
        {
            Random rand = new Random();

            for (int i = clients.Count - 1; i > 0; i--)
            {
                int rnd = rand.Next(0, i);
                ClientDataStruct val = clients[rnd];
                clients[rnd] = clients[i];
                clients[i]   = val;
            }
        }
Exemple #4
0
 public void RemoveClient(ClientDataStruct cl)
 {
     clients.Remove(clients.Find(x => x.ip == cl.ip && x.port == cl.port));
 }
Exemple #5
0
 public void AddClient(ClientDataStruct cl)
 {
     clients.Add(cl);
     ShuffleList();
 }
 public void Delete([FromBody] ClientDataStruct cl)
 {
     pool.RemoveClient(cl);
 }
 public void Post([FromBody] ClientDataStruct cl)
 {
     pool.AddClient(cl);
 }