Recent

Author Topic: Creating a p2p network  (Read 36632 times)

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Creating a p2p network
« on: January 06, 2014, 10:38:58 am »
Hi everyone;

I want create a program able to stablish p2p conections where users can send and receive simple information (just strings, like "Hello my name is Mike") between them using a secure conection (SSL maybe) Are there any examples? Any orientation about how i can build this is very grateful.

Since i dont have experience with networking development please be as clear as you can.
« Last Edit: January 06, 2014, 10:45:32 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Creating a p2p network
« Reply #1 on: January 06, 2014, 12:56:18 pm »
Have you read the wiki page on Synapse? Perhaps you want to look as well for "synapse chat example lazarus" with your preferred search engine. As far as I know there is an example distributed with the source code.

Since i dont have experience with networking development please be as clear as you can.
Please ask specific questions to get clear answers ;-).
Lazarus 1.7 (SVN) FPC 3.0.0

jarto

  • Full Member
  • ***
  • Posts: 106
Re: Creating a p2p network
« Reply #2 on: January 06, 2014, 01:00:26 pm »
I'll try to write about the big picture. First you need to make a server. You can do that using Indy's TTcpServer or Synapse's sockets. Indy is bigger but it usually is an easier way to start. Synapse is smaller but with it you need to do a lot more yourself.

Basically with both the idea is that the server creates a listening socket that listens to port number you decide. When a connection to that socket arrives, your server creates a new thread to handle that connection. The thread itself will read and write to that socket. So, if you have 10 connections to your server, you'll end up having 10 separate threads talking to those connections. Inside a thread you basically then only read and write until the connection is closed.

A good way to start is to make the server first. You don't need to make the client at the same time as you can test your server by using telnet:

1. "telnet localhost your_port" should make your server create the listening thread
2. write something and press enter -> your server should read what was written
3. write to the connection from your server -> it should be shown in the telnet window
4. close the connection from your server -> telnet should say that connection closed

When the server works well, you can start writing your own client software. It's basically just a simple tcp socket. Indy and Synapse both have easy to use ones. In the client socket you specify host and port and do a connect. And after that it can read and write to the socket pretty much like the socket on the server side.

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #3 on: January 06, 2014, 02:21:27 pm »
ok, i downloaded indy package and installed it in lazarus v 1.0.14

I put a TIdTCPserver on my form and set values:
active: true
default port: 8080

when i run the program, my firewall told me that one program was requesting autorization.

I wrote "telnet localhost 8080" and CMD witndow showed me "200 Welcome"
When i close the CMD window, my program told me that a connection was closed gracefully.

I assume i was able to connect to the server.

I added a simple image which is visible when i connect and hides when i disconnect. It works perfect  :)

Now i want that my programs show in the screen any text i write in the telnet console; it minds, be able to read what the client "says".
« Last Edit: January 07, 2014, 02:06:05 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

jarto

  • Full Member
  • ***
  • Posts: 106
Re: Creating a p2p network
« Reply #4 on: January 06, 2014, 03:17:28 pm »
Great. That's progress :-)

Maybe these example can get you further:

http://sourceforge.net/projects/indy10clieservr/

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #5 on: January 06, 2014, 05:03:08 pm »
OMFG! Its working!  :o

I thing the worst part is over, i understand now how it works!

EDIT

Ok, i have a "stable" server now, compiled and able to accept multiple client conexions.

Before try to make the conection secure (SSL implementation) i will focus on try to know how it works in real life. I mind, with real IPs. How the server and the client could know their own IP? Not netwrok IPs (127.0.01) but internet ones.

Also, i dont have experience with p2p networks. To make it stable, should i add one server and many client conecctions in the program?

I cant believe that in few hours i was able to do all this! Thanks a lot!

EDIT 2: I was able to get the client local IP when it connects using:
Var
Newclient : string;
begin
   Newclient := AContext.Connection.Socket.Binding.PeerIP;
end;

But im only able to work using local IPs (IE 10.0.0.35) If i set the client to connect to my external IP (ie 241.210.x.2 it did not work (my server is open of course) How i can fix this?

Also, if i set the IP for my port := 241.210.x.2 i get an error that address and port are already in use  :(

I checked the internet the last hours but i was unable to find nothing to fix this.
« Last Edit: January 07, 2014, 03:01:12 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Creating a p2p network
« Reply #6 on: January 07, 2014, 05:27:38 am »
Is your external IP on a card on your working machine? is it on a rooter if yes does it support NAT or port forwarding?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #7 on: January 07, 2014, 05:47:40 am »
I connect to internet via router but i dont have idea if it supports NAT or port forwarding.  :(

EDIT: I need configure my router? It is not possible to configure it directly from my aplication? I know there are many aplications that allows p2p conections throught a router without change the configuration of it.

EDIT 2: Mayve i need use a IdServerIOHandlerSSLOpenSSL1? Im in the right way?
« Last Edit: January 07, 2014, 06:13:32 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Creating a p2p network
« Reply #8 on: January 07, 2014, 06:12:45 am »
those application and the router must support UPNP or NAT-PMP protocols to auto setup the router there are no libraries tthat implement those protocols that I know of.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #9 on: January 07, 2014, 07:19:01 am »
Well, im learning more aboyt networkig development in the last 24 hours that what i learned in all my life.

Can a "tunel" be created using lazarus? Any library? Im actually trying with devart secure bridge.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Creating a p2p network
« Reply #10 on: January 07, 2014, 07:30:42 am »
yes but with out UPNP or NATPMP you have the same problems with your router's port forwarding.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #11 on: January 07, 2014, 07:44:47 am »
yes but with out UPNP or NATPMP you have the same problems with your router's port forwarding.

I spent the last 15 years developing amateur stand-alone games, UPNP/NATPMP is almost unreadable for me.
Secure bridge is not an option since is not freeware.
Can i have an example of lazarus program that created sucessfully a tunel? I mean, i can use emule in my PC or any chat app (mIRC is a good example) so this apps are able to stablish a tunel (i dotnt need open ports manually in my router when i install it)

Maybe i must made a better explanation of what i want from my app:

A lot of people is connected p2p from their homes.

Tom
Mike
Billy
Peter
....

If Tom sends a string to the network, all the other users receive it and knows who is sending it. Also, all users have a copy of all the strings on their own machine. Something like a chat but without personal messages (all strings are for all users)

Can it be implemented in lazarus to be used for everyone? Or it is needed that everyuser reconfigures his router? (most users dont have idea how to reconfigure router ports)
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Creating a p2p network
« Reply #12 on: January 07, 2014, 07:58:33 am »
Sorry I do not have any sample tunnel that I can share. As for the rest google UPNP http://www.upnp.org/ and natpmp http://files.dns-sd.org/draft-cheshire-nat-pmp.txtfor more information.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Creating a p2p network
« Reply #13 on: January 07, 2014, 08:30:25 am »
Very sad, looks like i will not be able to create my app in lazarus  :( :( :(

If i reconfigure my ports and use my machine as a server, the clients will need to reconfigure their router too?
I guess the clients will be able to send information to the server, even if the server can not send nothing back.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Creating a p2p network
« Reply #14 on: January 07, 2014, 08:46:57 am »
Yes clients will be able to send and receive information from a server as long as the port the server uses is not blocked by their firewall.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018