Module: Network - ninazeina/SXP GitHub Wiki
The network module provides all the networking services. It serves to:
- advertise the existence of some objects, whose full content is backed up by one or several peers.
- It serves to search amongst these advertisements, and ask for the corresponding objects from the peers that back it up.
- Demand modification of an object from a peer; perform such modifications yourself. (TO DO)
The network module is used by controller.manager.NetworkManagerDecorator
in order to enforce all communication mechanisms.
The network module is currently interfaced with JXTA but has been designed to be interfaceable with any other p2p protocol. JXTA technology is a set of open protocols that allow any connected device on the network (smart phones, tablets, pc...) to communicate and collaborate in a P2P manner. JXTA peers create a virtual network where any peer can interact with other peers and resources directly even when some of the peers and resources are behind firewalls and NATs or are on different network transports.
The most common and widely understood component of any P2P system is the peer. A peer is simply an application, executing on a computer device, that has the ability to communicate with other peers. For the entire system to work, it is fundamental that the peer have the ability to communicate with other peers.
In SXP, one has to distinguish a node from a peer or a user. A node is associated with one physical server implementation on the p2p network. A peer is a logical node. It can be seen as a node with services. And a user is just a model item.
Three others concepts should be clearly distinguished : pipes, peergroups and service. A set of peers is a peergroup. This is just a collection of peers. A peergroup can be created in order to share a same functionality. This functionality is then called a service. A service is proposed by a peer and used by a peergroup. It defines a "sub-network" shared by peers in which they can communicate with messages and advertisements. For communicating, a service uses a pipe. Like UNIX pipes, pipes are channels in which two or more peers can communicate.
The communication between peers is done by advertisements or messages. When peers have services they want to make known to the P2P network, they use an advertisement. It is a document that describes the service. It is broadcasted by a peer through a pipe to the whole peergroup and it does not lead to a response. A message is a packet that contains a payload of formatted data. They are used in pipes between peers for information exchange. Then, unlike advertisements, messages are sent to and received from localized peers.
-
api: interfaces for the different network elements.
- api.annotation: interfaces for the annotations that are include in the elements.
- factories: contains the factory for the peers.
-
impl: concrete implementations of the interfaces.
- impl.avertisement: concrete implementations of the different advertisements.
- impl.jxta: concrete implementations of the different network elements for JXTA protocoles.
- impl.messages: concrete implementation of the message iterface.
- utils:
When the application is launched the network.factories.PeerFactory
calls its createAndStartPeer
method that instantiates a network.impl.jxta.JxtaPeer
and starts it. The starting of the peer also starts the node that is referenced on a boostrap file by JXTA as a Rendez-Vous protocol. Then JXTA is finding other peers and building the network for the "SXP group" (see network.impl.jxta.JxtaNode.createDefaultGroup()
).
The peer starts two pipes associated with two services of network.impl.jxta.JxtaService
type. The first service, network.impl.jxta.JxtaItemService
, is used for searching items. The second one, network.impl.jxta.JxtaItemsSenderService
, is used for exchanging items.
Currently, the user creation and loggin operations are not connected to the network. It means that these operations are done locally. A user can not logged from another node.
When a user add an item, its request activates the Items.add()
method. This method also activates the controller.managers.NetworkItemManagerDecorator.persist()
method which is in charge of publishing the associated network.impl.advertisement.ItemAdvertisement
.
The network.impl.advertisement.ItemAdvertisement
is annotated by the network.api.annotation.ServiceName
annotation with name = "items"
. This annotation allows the network.impl.jxta.JxtaPeer
to find the right service to call for publishing the advertisement. Actually, the publication is done by the network.impl.jxta.JxtaService.publishAdvertisement()
method.
When a user is looking for an item, the controller.Search.ChunkedOutput<String> chunckedSearchByTitle2()
method is activated that calls the distant search controller.managers.NetworkItemManagerDecorator.findAllByAttribute()
method. Thanks to the decorator mechanism instantiated by model.factory.ManagerFactory
the local search is also activated by calling the model.syncManager.AbstractSyncManager.findAllByAttribute()
method.