Example #1
0
        static void Main(string[] args)
        {
            ConsoleHelper.WriteLine("输入s启动服务器");

            var input = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(input) || input.ToLower() != "s")
            {
                ConsoleHelper.WriteLine("输入服务器地址,例如:180.122.325.21:39654");

                var ipPort = ConsoleHelper.ReadLine();

                Peer peer = new Peer(ipPort);
                peer.OnConnected += Peer_OnConnected;
                peer.OnMessage   += Peer_OnMessage;


                ConsoleHelper.WriteLine("输入PeerB地址,例如:180.122.325.21:21541");

                var pIPPort = ConsoleHelper.ReadLine();

                peer.RequestP2P(pIPPort);
            }
            else
            {
                P2PServer p2pServer = new P2PServer();
                p2pServer.Start();
                ConsoleHelper.WriteLine("回车关闭测试");
            }

            ConsoleHelper.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Logger = new Logger()
            {
                MinLogLevelToDisplay = Configurations.Config.MinLogLevelToDisplay,
                MinLogLevelToSave    = Configurations.Config.MinLogLevelToSave
            };
            Services.Services.RegisterSingeleton(typeof(ILogger), Logger);

            LoadCommandLineArgs(args);

            Services.Services.RegisterSingeleton(typeof(IWalletService), new WalletService());

            Server = new P2PServer();
            Services.Services.RegisterSingeleton(typeof(IP2PServer), Server);
            Services.Services.RegisterSingeleton(typeof(IMappingService), new MappingService());
            Server.Start();
            Logger.Log("Starting up node...");

            if (true)
            {
                var mck = new MockClient();
                mck.MockTest();
            }

            Console.ReadLine();
        }
Example #3
0
    private IP2PServer method_9(int int_4)
    {
        P2PServer class2 = new P2PServer();

        class2.Initialize(int_4);
        return(class2);
    }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, P2PServer p2PServer)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc();

            string peersCSV = Configuration["Peers"];

            p2PServer.PopulatePeers(peersCSV);
            p2PServer.Listen();
        }
Example #5
0
 public string signalingServer = "wss://nameless-scrubland-88927.herokuapp.com"; // Please use a different server, this is mine but I'll let people use it for testing
 // Use this for initialization
 void Start()
 {
     server = new P2PServer(signalingServer, roomName);
     server.OnReceivedMessage += Server_OnReceivedMessage;
     server.OnConnection      += Server_OnConnection;
     server.OnDisconnection   += Server_OnDisconnection;
     curTime = Time.time;
 }
Example #6
0
 /// <summary>
 /// Entry point for our programme
 ///
 /// (Business logic, code behind, models...
 /// ...whatever you kids are calling it these days)
 /// </summary>
 public Main()
 {
     server = new P2PServer(1000);
     client = new P2PClient();
     server.OnConnectionSuccessful += SetClientFromServer;
     lewCoins = new BlockChainObj(client);
     Task serverConnection = Task.Run(() => server.Start());
 }
Example #7
0
        static void Main(string[] args)
        {
            P2PServer server = new P2PServer(IPAddress.Any, 8090);

            Console.WriteLine("服务已启动");
            server.StartListen();


            Console.ReadKey();
        }
        public Program(BlockChain _blcokchain, P2PServer _p2pServer, IConfiguration Configuration)
        {
            int    PORT = 55051;
            string IP   = "127.0.0.1";

            blockchain = _blcokchain;
            p2pServer  = _p2pServer;

            p2pServer.IP   = IP;
            p2pServer.PORT = PORT;
            string csvPeers = Configuration["Peers"];

            p2pServer.PopulatePeers(csvPeers);
        }
Example #9
0
        static void Main(string[] args)
        {
            P2PServer server = new P2PServer(
                hostName: Dns.GetHostName(),
                port: 8900);

            server.OnBlockAccepted       += (sender, eventArgs) => Console.WriteLine($"Accepted block:\n{JsonConvert.SerializeObject(eventArgs.Block, Formatting.Indented)}\n");
            server.OnTransactionAccepted += (sender, eventArgs) => Console.WriteLine($"Accepted transaction:\n{JsonConvert.SerializeObject(eventArgs.Transaction, Formatting.Indented)}\n");

            server.Start();

            Console.ReadKey();

            server.Stop();
        }
        public void TestIllegalConnectionHandshake()
        {
            var moq = new Mock <P2PServer>(() => new P2PServer(5500));

            moq.Setup(s => s.StartSendTask()).Returns(Task.CompletedTask);
            var obj     = moq.Object;
            var msgs    = obj.msgs;
            var handler = new ServerHandlers(obj, new Logger <ServerHandlers>(LoggerFactory.Create(b => b.AddConsole())));
            var bytes   = P2PServer.CreateUdpRequestBuffer(0, Guid.Empty, new ConnectionReplyDto
            {
                Acc = true,
                Ep  = PeerEP.ParsePeerEPFromIPEP(new System.Net.IPEndPoint(100, 100))
            });

            handler.HolePunchRequest(new UdpContext(bytes.AsMemory()[20..].ToArray(), new(),
Example #11
0
        static void Main(string[] args)
        {
            var server = new P2PServer();
            var client = new P2PClient();
            var resp   = Console.ReadLine();

            if (Uri.IsWellFormedUriString(resp, UriKind.Absolute))
            {
                blockchain.AddGenesisBlock();
                client.Connect(resp);
            }
            else if (int.TryParse(resp, out var port))
            {
                server.Start(port);
            }
            Console.ReadLine();
        }
Example #12
0
    // Use this for initialization
    void Start()
    {
        p2pClient = new P2PClient("127.0.0.1", 3005);
        p2pServer = new P2PServer(3005);

        Game.RTM = this;
        //	t=new Thread(Program.Init);
        //	t.Start();
        //StartCoroutine(PRI());
        GameObject.DontDestroyOnLoad(this.gameObject);
        //Game.PlaySound("Bell1");

        DbAccess.OpenDB("Db.db");
        IDataReader idr = DbAccess.SQL("SELECT * FROM Subx");

        if (idr.Read())
        {
            Debug.Log(idr.GetString(idr.GetOrdinal("Name")));
        }
        //IDataReader idr= DbAccess.SQL("");
        //idr.GetByte(idr.GetOrdinal());
    }
        static void Main()
        {
            //if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Count() <= 3)
            //{
            //    Process.Start("Tesis_Blockchain_VoteSystem.exe");
            //}
            VoteChain.InitializeChain();
            if (Server == null)
            {
                Server = new P2PServer();
                Server.Start(Program.Port);
            }
            else
            {
                Client.Connect(Server.url + "/BlockChain");
            }

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());
        }
Example #14
0
	// Use this for initialization
	void Start () 
	{
	

		p2pClient=new P2PClient("127.0.0.1",3005);
		p2pServer=new P2PServer(3005);

		Game.RTM=this;
	//	t=new Thread(Program.Init);
	//	t.Start();
		//StartCoroutine(PRI());
		GameObject.DontDestroyOnLoad(this.gameObject);
		//Game.PlaySound("Bell1");

		DbAccess.OpenDB("Db.db");
		IDataReader idr= DbAccess.SQL("SELECT * FROM Subx");

		if(idr.Read())
		{
			Debug.Log(idr.GetString(idr.GetOrdinal("Name")));
		}
		//IDataReader idr= DbAccess.SQL("");
		//idr.GetByte(idr.GetOrdinal());
	}
Example #15
0
 public void InitializeDaemon()
 {
     //Start P2P
     P2PClient = new P2PClient();
     P2PServer = new P2PServer();
 }
Example #16
0
 public BlockController(BlockChain _blockChain, P2PServer _p2pServer, IConfiguration _configuration)
 {
     this.blockChain    = _blockChain;
     this.p2pServer     = _p2pServer;
     this.configuration = _configuration;
 }
Example #17
0
 public DITestHandler(P2PServer server, string distring)
 {
     p2PServer = server;
     diString  = distring;
 }
Example #18
0
        static void Main(string[] args)
        {
            GhostCoin.InitializeChain();

            if (args.Length >= 1)
            {
                Port = int.Parse(args[0]);
            }
            if (args.Length >= 2)
            {
                name = args[1];
            }

            if (Port > 0)
            {
                Server = new P2PServer();
                Server.Start();
            }
            if (name != "Unkown")
            {
                Console.WriteLine($"Current user is {name}");
            }

            Console.WriteLine("=========================");
            Console.WriteLine("1. Connect to a server");
            Console.WriteLine("2. Add a transaction");
            Console.WriteLine("3. Display Blockchain");
            Console.WriteLine("4. Exit");
            Console.WriteLine("=========================");

            int selection = 0;

            while (selection != 4)
            {
                switch (selection)
                {
                case 1:
                    Console.WriteLine("Please enter the server URL");
                    string serverURL = Console.ReadLine();
                    Client.Connect($"{serverURL}/Blockchain");
                    break;

                case 2:
                    Console.WriteLine("Please enter the receiver name");
                    string receiverName = Console.ReadLine();
                    Console.WriteLine("Please enter the amount");
                    string amount = Console.ReadLine();
                    GhostCoin.CreateTransaction(new Transaction(name, receiverName, int.Parse(amount)));
                    GhostCoin.ProcessPendingTransactions(name);
                    Client.Broadcast(JsonConvert.SerializeObject(GhostCoin));
                    break;

                case 3:
                    Console.WriteLine("Blockchain");
                    Console.WriteLine(JsonConvert.SerializeObject(GhostCoin, Formatting.Indented));
                    break;
                }

                Console.WriteLine("Please select an action");
                string action = Console.ReadLine();
                selection = int.Parse(action);
            }

            Client.Close();
        }
Example #19
0
 void Start()
 {
     server = new P2PServer(serverURL, roomName);
     server.OnReceivedMessage += Server_OnReceivedMessage;
 }