Monday, August 3, 2015

P2P app with dartlang?

I studied whether it was possible to make p2p application at dartlang. I wonder because it is a thing possible?

After I studied. using chrome extension for application package that is better choice. 
Actually,  I created UPnP port map application. It was confirmed that P2P communication is possible.


Which network API shoud be used?

I'd think that you should useally use dart:io package, if create network application.
1
2
// It's declared by such feeling.
import 'dart:io'

But, This way has problem. It could not use dart:html package with dart:io packge.This is dart library restriction. We can not create a GUI application simply. it's very inconvenient.

I thought that chrome extension api is used. chrome api has rich network api. and chrome api application convert other platform, ios , android and chrome book etc.

- https://developer.chrome.com/apps/app_network
- https://github.com/MobileChromeApps/mobile-chrome-apps/blob/master/docs/APIStatus.md



Necessary condition of  P2P application.

What is the condition to have to fill it as p2p application? It's able to communicate data directly between the terminals. It is a p2p definition, isn't it?

But, It's unexpected difficultly. The realization is difficult.


Router(NAT) interfere with direct connection.

when we are accessing network, we must to use router?  In the most cases, Router assinged local ip to our pc. this local ip address is different ip in outside.

Let's try

1
2
// on command line app
netstat

IP addres us displayed such as  "192.168.100.1" , "10.00.101.1" ,etc. this address is for private network. Event if tell this address to some person, It isn't possible to access. This ip address could  be used in device with same the router.

Become connectable by UPnP

Router know global ip.  you could  be taught to the router!! Most of router has the ability to  communicate  at upnp protocol.


About UPnP Portmap

UPnP protocol need udp and tcp socket.
- use udp multicast to know router address.
- use tcp to request router.


search router

1
2
3
4
5
6
// request  at udp
M-SEARCH * HTTP/1.1
MX: 3
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
ST: urn:schemas-upnp-org:service:WANIPConnection:1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// response at udp
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1800
ST: urn:schemas-upnp-org:service:WANIPConnection:1
USN: uuid:E8088BD3-E808-8BD3-A042-E8088BD3A042::urn:schemas-upnp-org:service:WANIPConnection:1
EXT:
SERVER: E588 UPnP/1.0 MiniUPnPd/1.6
LOCATION: http://192.168.100.1:54616/rootDesc.xml
OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01
01-NLS: 1
BOOTID.UPNP.ORG: 1
CONFIGID.UPNP.ORG: 1337
DATE: Sun, 14 Sep 2014 00:42:14 GMT

request port map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// request at tcp
POST 192.168.100.1 HTTP/1.1
Host: 192.168.100.1
Connection: close
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
Content-Length: 629

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV:="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><m:AddPortMapping xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewRemoteHost></NewRemoteHost>
<NewExternalPort>48083</NewExternalPort>
<NewProtocol>TCP</NewProtocol>
<NewInternalPort>8083</NewInternalPort>
<NewInternalClient>192.168.100.100</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>test</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</m:AddPortMapping></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// response at tcp
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Connection: close
Content-Length: 263
Server: E588 UPnP/1.0 MiniUPnPd/1.6
EXT:
DATE: Sun, 14 Sep 2014 01:39:27 GMT

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddPortMappingResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"/>
</s:Body>
</s:Envelope>


get global address


1
2
3
4
5
6
// request at tcp
POST 192.168.100.1 HTTP/1.1
Host: 192.168.100.1
Connection: close
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"
Content-Length: 324


1
2
3
4
5
6
7
8
// response at tcp
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Connection: close
Content-Length: 360
Server: E588 UPnP/1.0 MiniUPnPd/1.6
EXT:
DATE: Sun, 14 Sep 2014 01:46:07 GMT

Let Implements!!

- source
https://github.com/kyorohiro/dart_hetimanet/tree/master/lib/src/upnp
- sample app
https://github.com/kyorohiro/dart_hetimanet/tree/master/example/HetimaPortMap

Safely, communication between the terminals could confirm!! By using Dart & Chrome extension. I found out that P2P application can be made easily.


PS 

release HetimaPortMap in chrome store. 



- Chrome Store
https://chrome.google.com/webstore/detail/hetimaportmap/naifildeohmcocnmibaampijofhcohif

- Google Play(now testing version)
https://play.google.com/store/apps/details?id=net.hetimatan.dart.portmap


-------
Kyorohiro work



No comments:

Post a Comment