-
Notifications
You must be signed in to change notification settings - Fork 0
Peer side API
We want to hide as much complexity as possible from application developers. We make it short. We only describe the least complex and also the best way to work with a hub in your ASAP based application. You need to setup the system first. It is just a single code line to connect to and disconnect from a hub.
We assume, you are already familiar with our ASAPEncounterManager.
Here is the code you should copy into your application.
SharkPeer sharkPeer = ...; // there is a peer
ASAPPeer asapPeer = sharkPeer.getASAPPeer(); // there is always an ASAP peer inside
// we need also the peer in its role of a connection handler
ASAPConnectionHandler asapHandler = (ASAPConnectionHandler) asapPeer();
// setup the system
// create an encounter manager
ASAPEncounterManagerImpl encounterManager = new ASAPEncounterManagerImpl(asapHandler, asapPeer.getPeerID());
// create a hub manager on peer side and link it with encounter manager
HubConnectionManager hubConnectionManager = new HubConnectionManagerImpl(this.encounterManager, asapPeer);
Now we are ready to work with a hub.
A peer can be connected to a hub by calling a single methode: hubConnectionManager.connectHub
. It requires a single parameter, a HubConnectorDescription. It is a simple data structure comprising parameter required to access a hub.
HubConnectorDescription hcd = new TCPHubConnectorDescriptionImpl("localhost", 6666, true);
hubConnectionManager.connectHub(hcd);
This code would try to establish a connection to a hub available on the same machine with an open TCP port on 6666. Nothing more to do for app developers.
A new connection attempt would be redirected to the encouter manager. It would briefly check if a new ASAP session is useful. The actual ASAP session would be performed by its ASAP peer.
hubConnectionManager.disconnectHub(hcd);
This code breaks the connection to the hub.
List<HubConnectorDescription> hcdList = hubConnectionManager.getConnectedHubs();
You can get a list of hub connections which are actually in place.
Actually, we do not know how you will use hubs in your application. We consider hubs a more fluent entity. It is launched, runs a while(minutes, hours, maybe days) but disappears soon.
The obvious question is a version of the chicken-and-the-egg problem. Where would we get information on a hub in the first place. Once we have it, we can disseminate information on next hubs in our application. But how to find the first.
There are two sub-project in place:
- We send hub information in social networks steganographic hidden. It is, of course, not a perfect safe solution. But it could be useful in some application classes.
- We use a P2P system like libp2p / disc to provide hub descriptions. Those information are public.
It always depends on your application requirements. At least, you can chose.
Anyway, we need a way to make hub descriptions persistent on a peer. Good news. A SharkPeer can remember and forget.
SharkPeer sharkPeer;
// remember
sharkPeer.addHubDescription(hcd);
// forget
sharkPeer.removeHubDescription(hcd);
TODO
Have a look in our test package for further examples.