Home > Articles > Programming > Java

Building P2P Applications

Examine a variety of P2P applications and the architectural issues that need to be resolved in order to build them.
This chapter is from the book

In This Chapter

  • Instant Messaging

  • Managing and Sharing Information

  • Collaboration

  • Distributed Services

Chapter 1 introduced the wide world of P2P. It might have appeared that the definition of P2P is problematic—well, it is! P2P can be so broad in scope and definition that getting one's arms around P2P can be an enormous task. P2P came about as an answer to user needs for Internet-enabled application software. The Internet is always evolving and offering up new technologies, techniques, and user behavior every day. P2P is evolving along with the Internet, so fixed definitions do not usually last long.

Each new advance in Internet technology can either help Java developers working on Internet applications, or become a huge headache. For example, there was a time when Network Address Translation (NAT) routers were banned from networks. As you will see later in this chapter, they are now used widely, and a Java developer building a P2P application needs a solution to the unique one-way routing provided by a NAT router.

An easy way to get your arms around a P2P definition is to look at the functions delivered by the most notable P2P applications, including the following:

  • Instant messaging

  • Managing and sharing information

  • Collaboration

What started out as simple file sharing, such as exchanging music files, has grown to include a wide array of applications and services. These are grouped under the umbrella term distributed P2P services. These include network and infrastructure software to enable

  • Distributed processing (grid computing)

  • Distributed storage

  • Distributed network services

Although many of these applications began as ways to distribute stolen copyrighted music and video files, P2P has reached a level of maturity that is no longer confined to personal, casual use, but rather to build e-market hubs, corporate infrastructure, and Internet-enabled applications. In addition, single-function P2P applications are giving way to multifunction service-based architectures. For instance, it is common to aggregate instant messaging, file sharing, and content management to build distributed collaborative P2P applications.

Next we will look in depth at these applications and the technology that enables them.

Instant Messaging

Although Web publishing and browsing is the killer application for the Internet, instant messaging is the killer application for P2P. Instant messaging (IM) enables online users to communicate immediately and in real-time, one-to-one or in a group. It has become popular on the Internet among young adults, and is gaining popularity in business settings, too. For example, even IBM's Lotus group offers an IM product for business use. IM has gained recognition as a useful application, and most major Internet players offer IM services—AOL, Microsoft, and Yahoo! all offer IM functionality. New players are promoting niche products for e-commerce and supply chain management. There has been some market consolidation as lesser offerings have been eliminated, but there is still tremendous growth and opportunity.

With IM, users activate a special piece of client software that communicates with a central server and registers the user as being online. This user registration is mapped to an identity, such as a nickname or screen name. The user is then able to invite others to a conversation, or can be invited. IM servers communicate using an IM server protocol that enables messages to be relayed across the Internet. This interconnected IM network forms an IM cloud, or backbone, as seen in Figure 3.1. Most servers support a proprietary protocol, which has made it difficult for IM users to communicate across multiple IM systems.

Figure 3.1 Traditional instant messaging systems enable users to exchange messages through a proprietary IM cloud.

Unlike email, in which a message is stored and delivered once the user has connected to an email server, IM systems provide immediate end user delivery. If the user is not available, the message can be saved until the user comes online, or it simply may be discarded. To avoid this uncertainty in delivery, IM systems provide a "buddy list" or roster that provides a mechanism to identify a user and determine the user's online status: for example, online, offline, or unavailable.

If the user is online, you can send text messages that are immediately delivered to the user. This promotes a two-way conversational style of communication with minimal delay. Tight integration between clients and servers enables instant messaging services to provide varying levels of security, online status, and reliable messaging, as seen in Figure 3.2. The client protocol defines the message structure necessary to communicate short text messages. The server protocol defines the higher-level services, such as routing, presence, and security.

Figure 3.2 Instant messaging systems define a client and a server protocol.

Applications of presence (online status) and instant messaging currently use independent, nonstandard, and non-interoperable protocols developed by various vendors.

Technology

Under the covers, IM systems provide identity, presence, and security using IM protocols.

Identity

Fundamental to the operation of any IM system is the need to uniquely identify users. IM identity is modeled much like email identity. For instance, your email address might be myName@domain.com. Similarly, your instant messaging address might be identified by myName@imdomain.com. IM systems support name aliases to simplify usage, so myName@imdomain.com can be aliased to p2pgeek. The server or client maintains a mapping between addresses and aliases to make the system more user friendly.

Presence

Presence is the online state of a user or application. Presence is a concept important to conversations, because it enables participants to enter or leave a conversation, and make other participants aware of their status.

A presence service provides a means for finding, retrieving, and subscribing to changes in the presence information of other users. This is especially important with instant messaging systems. Presence determines whether a specific user is online and available, whereas identity uniquely identifies that user within the specific IM domain.

Presence services are becoming more sophisticated, and are not limited to simple online/offline state information. Contextual information can be maintained to convey location, activity, and application-specific data. Presence information provides the context necessary to support P2P conversations. In addition, sophisticated presence services can provide status, identity, and location information to enable application-to-application communication.

Buddy lists are part of IM presence technology. A buddy list, also called a roster, defines a list of members of your messaging group or community. Members of your roster may be colleagues, friends, or associates that you communicate with regularly. They ultimately are peers that you trust.

Interoperability

IM is all about dynamically and rapidly grouping users and applications together to form working teams. It is counterintuitive that IM service providers would cause their IM protocols to be closed and proprietary.

The popularity of instant messaging and the growth in instant messaging systems has resulted in an increased demand for IM interoperability. Most instant messaging systems work only if the sender and receiver are using the same instant messaging software.

The protocols defined to exchange information, such as presence, messages, and identity are proprietary to the vendor. Software developers have resorted to building gateways or multi-headed clients to integrate disparate systems. However, the complexity and maintainability of the client can be limiting. Figure 3.3 illustrates communication with the Internet Relay Chat (IRC), AOL Instant Messenger (AIM), and MSN systems.

Figure 3.3 Multi-headed clients enable a user to communicate with multiple IM systems.

Of course, this solution puts a heavy burden on the client software. The software must be able to interoperate with different messaging structures, presence and identity identification, and different feature sets and security models offered by IM providers. There are also legal ramifications to usage, spam implications, and resource sharing that must be considered.

An approach being promoted by some of the larger IM providers is to provide a mechanism for the services themselves to interoperate. This is similar to how email works today. The interaction between instant messaging clients and associated servers remains the same. However, servers communicate with other servers to exchange presence information, messages, or other data, as in Figure 3.4. This approach preserves existing IM models. In addition, it helps protect investment by the larger participants in established IM communities. Clients "speak" a proprietary protocol, but IM servers use a standard open protocol. Servers must mediate message and protocol disparities and serve as a gateway to other IM systems.

Figure 3.4 Interoperability is achieved at the service level.

The Internet Engineering Task Force (IETF) (http://www.ietf.org) is developing what will likely become the standard protocol for instant messaging, called the Instant Messaging and Presence Protocol (IMPP). The goal of the IMPP Working Group is to define a standard protocol, so that independently developed applications of instant messaging and/or presence can interoperate across the Internet. The requirements being addressed include the following:

  • Namespace and administration

  • Scalability and performance

  • Access control

  • Network topology

  • Message encryption and authentication

  • Internationalization

For more information, go to http://www.imppwg.org. Standardization work is progressing, but adoption has been slow as vendors try to secure a dominant position with their current product offering.

Security

Instant messaging does not define a mechanism for secure communication. However, many commercial IM vendors have incorporated Public Key Infrastructure (PKI) digital certificates to add security and privacy to IM communication. IBM Lotus Sametime, for example, moves IM protocols over Secure Sockets Layer (SSL) connections. Messages, connection information, and identity are maintained on servers administered and controlled by the provider of the IM service. Most services provide a certain level of encryption, but there have been numerous security breaches on IM systems. This is one area that is changing, as new P2P entrants attempt to differentiate their product offerings through enhanced security.

Products

Because instant messaging has become so popular, it is not surprising that there is an abundance of IM providers. Today, many P2P applications are including an instant messaging component. It is envisioned that as businesses link their manufacturing, distribution, and sales processes, more reliance on IM features will be the result. Many Web sites already use IM as a key component in their customer relationship management (CRM) strategy.

IRC

Internet Relay Chat (IRC, http://www.irc.org), is often cited as the original chat medium on the Internet. It is the forefather to many of the IM protocols that have been developed. The IRC protocol was designed for use with text-based conferencing. The IRC protocol is based on the client-server model. A server forms a central point for clients (or other servers) to connect to, and performs the required message delivery, multiplexing, and IM functions.

Over the years, IRC has been expanded and changed to resolve scalability problems. For example, while the original IRC protocol required a single central server, today's IRC enables federations of interconnected servers to pass IM messages. OpenProjects.net (http://freenode.net/) provides a backbone of IRC servers that developers and users working on open-source projects use. IRC continues to evolve.

AIM

AOL Instant Messenger (AIM) is one of the most popular instant messaging programs. With 30 million users and 2.3 billion AIM messages passed every month according to Juniper Media Matrix, AOL has the largest single installed user-base on the Internet. AIM is so large that AOL had to pledge to provide interoperability with other IM networks as a prerequisite to the Time-AOL merger. AIM is the best example of open standards and interoperability colliding with capitalism. Attempts to open the AIM network have clashed with AOL's modification of the protocol to remain incompatible. Even today, AOL has shown how slow it can be to open its network.

AIM technology is designed around a system of interoperating servers to route IM messages, provide presence service and security. AIM uses the AOL directory service for authentication and provides client software on several platforms.

Jabber

Jabber (http://www.jabber.org) is an open source instant messaging platform being developed by the open source community. One of the features that distinguishes the Jabber system from existing instant messaging services is its open XML protocol. The Jabber protocol has been submitted as an IETF Request For Comments (RFC).

Jabber is attempting to build the interoperable protocol that all IM vendors will support. This would enable the interoperability that is envisioned by the IM community. In the meantime, the Jabber architecture is built on pluggable transport modules that communicate with specific IM systems, as seen in Figure 3.5.

Figure 3.5 The Jabber architecture from http://www.jabber.com.

The idea is that you use the Jabber XML protocol (XMPP) from the client to the Jabber server, and the server loads an IM-specific transport module to interoperate with the proprietary IM system.

Jabber's XML protocol contains three top-level XML elements:

<message/>
<presence/>
<iq/> (info/query)

Each of these elements can contain additional attributes and namespace definitions that are part of the Jabber protocol. Jabber sessions are maintained through the exchange of XML streams, one from the client to the server, and one from the server to the client. All <message/>, <presence/>, and <iq/> elements are sent within the context of these XML streams. Here is an example from the Jabber specification:

SEND:<stream:stream
SEND:to='jabber.org'
SEND:xmlns='jabber:client'
SEND:xmlns:stream='http://etherx.jabber.org/streams'>
RECV:<stream:stream
RECV:xmlns:stream='http://etherx.jabber.org/streams'
RECV:id='39ABA7D2'
RECV:xmlns='jabber:client'
RECV:from='jabber.org'>
(XML for user session goes here) *
SEND:</stream:stream>
RECV:</stream:stream>

The Jabber protocol is designed to facilitate writing Jabber client code and conducting tests. Details on Jabber can be found at http://www.jabber.com. There you can download an applet that enables you to register with a Jabber server, as seen in Figure 3.6.

Figure 3.6 A Jabber client from http://www.jabber.com.

The Jabber architecture resembles email. A Jabber client is connected to a Jabber server. Like an email server, the Jabber server is responsible for the delivery and receipt of the client's messages. However, Jabber servers will attempt to deliver the messages immediately, thereby supporting instant messaging and conversational capabilities. The Jabber server will queue messages when a peer is unavailable or offline.

The peer-to-peer comparisons of Jabber are more appropriately realized with the relationship between Jabber servers. Every Jabber server is a peer to every other Jabber server. Jabber servers use a number of mechanisms to improve the integrity and security of the system. For instance, hostname dialback independently contacts the sending server to validate incoming data to prevent spoofing.

There are a number of Jabber clients available. Examples include the following:

You can find a list of public servers and their current status at http://www.jabberview.com/. For more information, visit http://www.jabber.org.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020