Está en la página 1de 15

Practical JXTA II

Cracking the P2P puzzle

data. without written permission from the publisher. strategies. electronic or mechanical. special. procurement of substitute goods or services. recording. or tort (including negligence or otherwise) arising in any way out of the use of the software code ex- amples. Inc. DawningStreams. Publisher: Lulu Enterprises. is not associated with any products or vendors mentioned in this book. 2010. except for the inclusion of brief quotations in a review. In no event. strict liability. Second edition: July. in the United States and other countries and may not be be used without permission. loss of use. Trademarks: DawningStreams. but not limited to. Inc.com) -2 . advice. including photocopying. the implied warranties or merchantability and fitness for a particular purpose are disclaimed. advice. indirect. All other trade- marks are the property of their respective owners. but not limited to. No part of this book may be reproduced or transmitted in any form or by any means. Inc. The software code examples. or consequential damages (including. International Standard Book Number: 978-1-4461-3956-1 Limit of Liability/Disclaimer of Warranty: While the publisher and the author have used their best effort in preparing this book. (www. whether in contract. 2008. including. or business in- terruption) however caused and on any theory of liability. strategies herein are provided “as is” and any expressed or implied warranties. be liable for any direct. or by any information stor- age and retrieval system. Inc. Inc. shall DawningStreams. The Netherlands First edition: July. No warranty may be created or extended by sales representatives or written sales materials. or profit. All right reserved. You should consult with a professional where appropriate. incidental.Practical JXTA II Copyright © 2010 by DawningStreams.lulu. even if advised of the possibility of such damages. exemplary. Inc. they make no representation or warranties with respect to the accuracy or completeness of the contents of this book. is a registered trademarks of DawningStreams.

...........................................................................................................................................................................................................32 JXTA......................................................................................................................32 Towards Universality ...................................................................................................................14 Prerequisites..................28 Initial Objectives and Evolution............................................................................................................................................................................................................44 Resources........................................................................................................................................................................................................................................................................................................................37 Documentation............................................26 Kazaa.............................................................................................................................................................48 Peer Group Advertisement......................12 Why A Second Edition?.................43 Service.........................................................................................................40 Overview............................................................................................................................................................21 Clustering & Load Balancing .................................................................................................................................................................20 Three-tier & Multi-tier ...............................................................................................................................................................34 Introduction......................................Table of Contents Foreword 11 Why This Book?..........................................................................48 ID...........................................................................................................16 A Bad Reputation?............41 Peer Group......................................................35 The JXTA Project........................................................................................................................................................................................37 Understanding JXTA 39 Introduction..................................................................................................................................................................................................30 So.......................24 ICQ......................................37 JXME..................................................................................................................... Forum & FAQ.....................................................................................20 Client/Server............................22 Grid Computing..............................30 Drawbacks..............................................................................................................................................................................................................................39 A Tribes-In-Islands Metaphor.............................................................................................................................................................................................................13 Who Should Read This Book?...........................36 JXSE Community.........23 What is P2P?........................................................................................................28 Freenet.............................................................................................................................................................................................................................................................................................................................................21 Service Oriented Architecture & Middleware.....................................25 Gnutella...............................................................................15 Introduction 16 Peer to Peer........................................................................................................................49 -3 ........................................................................................................................................27 BitTorrent................................................................................ What Is The Use of P2P?....................................................................................................................................................................................................................................................................................................................................................................................................................................................23 Cloud Computing............................................................................................................................................................................................................................................................................................................................................................................23 About Needs That Have Shaped IT Solutions....................................................................................................................................................................................48 Publication.........................................................................................................................................................................................................................................................................................................................................18 Architectures & Design Principles....................................................................................................................................................................47 Peer Advertisement.............................................................................................................................................................................................................................................34 The Three Layer Cake.........................................................................................................................................................................................................................................................................................................................................................24 Napster..................................................................................................................................................................................................................................................................................................39 The Concepts.................................................................................................................................................................................................................................................................36 C/C++...........................................................................................................................................................................................................................................................................................................................................................................................................................16 A Quick Historical Review..........................................................................................................................................................................................................................................................................................................................................................................40 Peer........47 Advertisement...........................................................................................................................................................28 Pure P2P........................................................................................................................................................................................29 Benefits..................................................................................................................................................................................................................................................................

...................................................................................................................71 Access Control.................................63 Pipe Binding Protocol (PBP)................................60 Rendezvous Lease Protocol..........................................................................................................................................................................50 Codats........................................................................................................................................................................................................................................................................................................58 PeerView Protocol...................................................................................52 Message...........67 Top-Down-Top.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................50 Pipes.................................................................................................................................................................................................................................................77 Network Boundaries 79 Reminder...............................................................................................................................................74 Bootstrapping JXTA..............................50 Module....................................................................................69 PIP Response Message.......................................................69 Top-Down-Top...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................68 Peer Information Protocol (PIP)..........................................................................................................................................................................................81 Handshake................................................66 Shared Resource Distributed Index (SRDI)....66 Resolver Response Message...................................................................................................................................81 UDP...............................................................................................................................................................................82 Datagram.........................................................................................................................................................................70 Discovery Query Response.......................................................................................................................................................................................................65 Peer Resolver Protocol (PRP).....................................................................63 Pipe Advertisement.................................................................................................. Specification and Implementation IDs.....................................................................................................................................................................................................................64 Propagate Pipe Message Header........................................................................................................................................................................................................................................................................57 Rendezvous Protocol (RVP).......................................................................................................................................................................................................................................................................................................................................................................................81 IPv4 Versus IPv6................................................................................................................................................................................................................................................................................................................................................................54 Endpoint Routing Protocol..................................................................................................................................74 Well-known Module Class...............................................................................................73 Service........72 The Ignition Process............................71 Membership Service..........................................................................................................................................53 Endpoint Address..................72 Access Service..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................53 Endpoint Routing Protocol (ERP).......68 PIP Query Message.................................................................................................................................................................................................................................................................................82 -4 ..................................70 Discovery Query Message..................65 Top-Down-Top............................56 Top-Down-Top..........................................61 Top-Down-Top.......................................................................77 Loading Other Services.................................................................70 Top-Down-Top..............73 Module................................................................................................................................................................................................................................ Content..........................................................................................................................65 Resolver Query Message...............................................................80 Unicast.................................................................................................................................................................................................................................................................................................................................................................................................................74 Peer Group As A Service – Part I......................................61 Propagation Control............................................................................................................................................50 The Protocols........................................79 IP...................................................................................................61 Peer Connection to Rendezvous ..................................................................................................................................................................................................................................................59 Rendezvous Advertisement.......74 Peer Group As A Service – Part II.............................66 Resolver SRDI Message.......................64 Pipe Resolver Message..................................................................58 Message Propagation Protocol. Broadcast & Multicast..............................81 TCP...............................................................................................54 ERP Messages & Advertisements..........................................................................................................................................................................................................................................................................................................................................53 Endpoint Service........................................................................................................................................................................................................................................................................................................................................69 Peer Discovery Protocol (PDP)..........................................................................

.91 Overcoming NATs......................................................................................90 Overcoming Firewalls.................................................108 RFC 4787....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................123 Hash Function..................................................................................................................................................................................................................................................................................................................................................................97 Port Prediction......................................................................................................................................................84 Some Limitations............109 Where Does JXSE Stand?.......113 Introduction To Secure Communication.............................................................................................................................................................................................................. Bob & Eve..................................................................................................................................................................................................................................................................................................................................................96 Same Subnet....................................96 Different Subnets.......106 UPnP..................88 Artificial Network Boundaries..................................................................................................................................................................................................................................................................................................................83 NAT.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................104 PWNAT..500 & Principal.....................................................................................................................................................................................................................111 JXSE Cryptographic Layer 113 Cryptography Reminder....................................................................................................................................................107 ICE......................................................99 TURN.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................87 Router..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................105 ALG...................................................................................120 Duties Of A Certificate Authority.....................................................................................................................................................................................................................................................................................................................113 Alice...........................123 -5 ...................................108 “Behave” Compliant NAT............................................................................107 ICE-TCP..................................................114 .............................................................................................................................................................................................................................................509................................86 Proxy...........................................................108 RFC 5382...............................................................................................................................................................120 Web Of Trust........................................................................................................................................................................................................................95 WAN.....................................................................................................................................................................................................................................................................................................103 NATBlaster.................................................................................................................................................................................................96 NAT Traversal..................................................................................................102 NUTSS...........................................................................................................89 JXTA Transportation Layer.......122 X.............................................................................92 Seeds................................................................................................................................................................................110 Conclusion...................................................................................................................99 STUN.......................................................................................................................................................................................................................90 Relay Service............................................................................................And Vicious Circles!.........................................................99 STUNT..........................................................................................................................................................................................................................................................................94 Peer Accessibility...............................................117 Public Key Infrastructure (PKI)..............................................................103 P2PNAT..................................................................................98 Hairpin Issue................................... Port.............................................................................................................................................................91 Overcoming Proxies..................................................................87 Natural Network Boundaries............................................................97 IP Obstacles..........................................................................................................................................................................................................................................89 JXSE Transportation Layer..................................................................................98 Punching Holes...............................87 Multicasting Versus Subnets........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................100 TTL-less Version of STUNT...........................104 NatTrav............................................................................82 Firewalls................................95 LAN................................102 New NAT Classification.........................................................................................................................................98 RFC 5128......................................................................................119 Who Certifies The Root Certificate Authority?......................121 X............................................................................................................................................................................................86 PAT...................................................................

................................................................................................................................................................................................................................................................................................152 -6 ......................................124 Key Sizes .......................................................................................128 Automatic X...............................................................................................................................144 EDGE.........134 Virtual Private Network (VPN)...........................................................................................................................................................................................................................................................149 Default HTTP Port......................................................................................................................................................................................................................................................................................................................................................................................................147 A RendezVous...............................................144 RENDEZVOUS..................................................................................................................................................................................................................................................................143 JXTA Peer Types..............151 Exportation Limitations...........................................................................................150 Implementing Seeds................................................................................................................................................................................................................................................126 Calling Experts..................................................................................................................................................................................................................131 Registering Your Own X..........................................................................................139 Defining An Identity in JXTA............127 Java Cryptography Architecture................................................................................509 Certificate & Private Key Creation............................................................................143 Rendezvous Peer.........................................................................................................................................................................149 Default IP Ports....127 KeyStore.................................................................................................................................145 RELAY.............................................................................................148 Number of Seeds..............................................................................................................................................................................................................................................................................................................................................................141 Peer Group Creation & Identity................................................................................................................................................................................................................141 Configuration Modes.................................................................................................................................................146 About Implementation Of Services..................................................................................................................................................................................................................................................................................144 ADHOC......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................132 Other Concepts...................................................................................................................................................................................................................................................................................................................................................147 To Be Or Not To Be?..........................................................................................................................................................................143 JXSE Configuration Modes..........137 Where Does JXSE 2..........138 Architectural Considerations 139 Identity Issues..........................................................................................................................................................................................................................132 PSE Configuration..................509.............................................................................................................................135 About Cipher Suites...................................................................................145 PROXY..........134 Transport Security Layer (TLS)......................................................................................................................................................................................................................................................................................................................126 Personal Security Environment (PSE).......................................................................................................................................................................................................................................................................................151 Implementing Your Own Cryptography Layer..................................................................................... The Collision Issue........................................................................................135 About Encryption of Private Keys...............................................150 Cryptography.............................................................................................................................135 PSE Configuration Advertisement Encryption...143 Relay Peer.140 Creation Of Peer IDs & Importation Of IDs From Other Systems...............................................................................................................................................................146 Network Scope...128 Big Big Big Warning!.........................147 A Relay...............................................................................................................................................150 About Subnets...................................................................................................................................143 Minimal Edge Peer.................................................................................149 Default Multicasting Port & IP Address..........................134 JXTA Security Layer.................................................125 The DRM Illusion...................................143 Full-Featured Edge Peer...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................151 Access Control Implementation...............................................................................................................................149 Network Administration..................................................................................................................................................................................................................................................................................................................................................................................................6 Stand?.........................................................146 Peer Type versus Configuration Types.................134 Secure Socket Layer (SSL)................................................................................................................................................................................125 Assumptions ......................................................................................................................................................................................................................................................................................................................................................................139 IP Addresses As Identities............................................................................................................................................................................................127 Creation.............................137 Conclusion.................................

.....................................................................................190 Local And Remote Publication...................................................................................................................................................194 Example 410 – Add String.....................................Retrieving And Flushing Local Advertisements......179 Robert....................................................................................................................................................................................................................................................... Then Anna...........................................................................................................................................183 Example 200 – Creating IDs.196 Example 440 – Adding An Advertisement In A Message...................... The Other Edge...........................................................................................................................................................................................................................................154 Example 100 ..........................194 Example 400 – Creating An Empty Message.........166 Running Multiple Peers On A Single Device...............................................................................167 Anna.......................................................180 Relay Connectivity..................................161 Exploring Connectivity Issues.....178 Connectivity Manager................................................202 Private Keys............ The Edge......................159 Automatic Change Of IP Addresses....................................................................................................................... Modifying & Saving A Local Configuration........................................201 Instantiator..................154 First Connection & Local Configuration..............................................185 Discovery Operations............................................................................... Certificates & KeyStores..............................................................................................................................................................................................................................................................................................................................................194 Example 420 – Retrieving Message Elements......171 Angle I ................................201 Methods.........................171 Angle II ......157 Miscellaneous............ The Rendezvous........................................................................................................................................................................................Using JXSE 153 Getting Started........................159 Loading A Configuration From A URI.................................................................................................................................................................................................................................................................................................................................................................... Keep Configuration & Disapprove Seed.. Delete Configuration & Approve Seed.....................................................................................................Starting And Stopping JXTA..............................................................198 Attributes...............................................................................................................................................................................................................................................................169 Testing Angles Between Jack And Anna............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Then Anna.................................................183 Example 210 – Creating A New Peer...........................................................................................................................................................................................197 Example 500 – Customized Advertisement.......................................................................................................................................................................................................160 Example 150 .................................................................................................... The Other RendezVous............................. The Relay.......................Start Anna...................................................................... Delete Configuration & Approve Seed...............................................................................................................................................188 Example 300 .................................................................174 Chihiro.................................................................................................................................................160 Example 160 – Connecting with OSGi.........................................................................................................................................................................................................................................159 Modifying Other Configuration Parameters..............................................................................................163 Creating & Using Seeds.............166 The Proper Angle To Strike A Match...................................................................................160 New Configuration Objects & Connecting With OSGi..............................................Configuration Objects...................................................................................................................................173 Aminah........................................................................................................................188 Finding Advertisements.....................................................................................................................194 Messages & Advertisements.........................159 Local Configuration Directory Structure....................................154 Example 110 – Creating A Local Configuration......................................................................................................................................... Then Jack......................................................................................................................................................................................................................................................................................................................153 Creating A Project...............173 Remarks & Warning..........................................................................................................184 Example 220 – Creating A Customized Peer Group............................................154 Javadoc.........................................166 Multiple Peer In The Same JVM..........................................................................................................................Start Jack.............................. Long & Int Elements......................159 Understanding ConfigParam................................................156 Example 120 – Retrieving..........................................203 -7 ........................153 Maven...................188 Example 310 – Remote Search For Advertisements.......................................................................................................175 Automatic Reconnection To Other RendezVous............................182 Creating Peers And Peer Groups.....................................................172 Angle III ...........................................................................182 Summary...........163 About The Default JXTA Seeds...................................................................................................................................202 Example 510 – Registering A Customized Advertisement Instance........................167 Jack.......................................................................................................................................................................................................Start Jack......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................195 Example 430 – Add Byte Array Element And Retrieve InputStream.................................................................

..................................250 About The Future.......................................................................................................................................... A Multicast Participant..........................................................................................251 Distributed Content.......................................................................................245 Ping............................................. The Edge Sending Messages.............................................................................................................................................251 About Needs That Have Shaped IT Solutions – Part II.......................................................................................................................213 Running The Example..........................................................................................................................................................................................................................................................................................................................................231 Running The Example.........................................................................215 Unicast Secure Pipes.................................................................................................................................................................................................................................................................................................................................................233 Introduction...........................................................................................................................................................................................................223 Lidong........................................................509 Certificates.250 JXSE Shell......................Universality.....................................................................................................252 Economical.....................................245 Example 800 – Ping....255 Accountability & Vendor's Credibility....................................................229 Teyacapan......................................................................................241 Running The Example.......................................................................................................................Exporting & Importing Private Keys And X..........................................................................................................................................................................................................................................................................................................................................................................................................................................................239 RendezVous Joe......................................217 Adelaide.....................................................................................................................................................................................................................233 Example 710 – Astrology Service ........................................... 251 ..................................................................................................................................................................................................................................................................................................................................................256 -8 ............................................................249 Miscellaneous.................................................................................... The RendezVous At One End............................................................................................................238 Static Methods.......................................................................................................................................................................................................239 Edge Jill............................................................................................................................211 Dimitri....................... Another Multicast Participant........ The Rendezvous.........................................................................................................244 Self-Service Weather Forecasting Method................203 Example 610 – Working With A KeyStore..239 Implementation Of Interfaces................229 Hans......247 Running the Example....................................................254 .............................................................................................................................246 Example 810 – Pong............................... The Edge At The Other End.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................220 Running The Example.................................................217 Bidirectional Pipe Communication..........................................................................................................255 Technological.........................................................................................................222 JXTA Socket & Socket Server..............................................................................................................................................234 Static And Non-Static Attributes....................................................................................................................................................................251 CHURN..252 Costs And Return On Investment.....................................239 Static Class.......................................................................................255 Educational..................................................................................................................................................................................................................................249 Sending A Message With The Endpoint Service............................................................. The Rendezvous And JXTA Socket Server.....................................................................................244 Peer Information............223 Ayrton......................................................................................................................................207 Simple Pipe Communication..................................................................................................249 About Registering Handlers In Services........................................................ The Customer ........................................................................................................................................................... Example 600 ................................................. The Astrologer ... Facts.............................................................................................................................................252 Potential For Profit............................................................................................................................................................................................................210 Chandra...............................................................................................................................................................................................233 Implementing A Customized Service..................................... The Rendezvous Listening to Messages.......................................................... The Edge And JXTA Socket.............................................................................................................................................................................................................................................................................................................................................................................255 Simplification Of Complexity ...249 Customized Queries.........................................................................................................................................................................................................................................................................................Of JXTA..228 JXTA Multicast Socket.......................................................................................................251 Perception vs...........................................................................226 Running The Example.....................................................233 Example 700 – Creating Module IDs.................................................Of P2P..........205 Example 620 – Custom PSE Peer Group & Joining ............................................................................255 New Applications.............................................................................................. The Edge................................................................................................................................................................217 Quinisela............245 Activation Of The Peer Information Service................................

...............................................................................................................................................................................................................................................................................................262 Module Class Advertisement................................................................................................................................................................................................................................................................................................................................................................................... Books And Tutorials...........................................................................................265 -9 ....................................................................................................259 Appendix 261 Protocol Messages Types.......................................................................................................................................................................................................................262 Module Implementation Advertisement .................................................................................................................262 Peer Advertisement....................................................................................... Documentation....................................................................257 The Protocols.......................................................................................................................................................................................................................................................................262 Peer Group Advertisement............................................................257 The Community...........263 Rendezvous Advertisement..........................................................................................................................................................................................................................................................................................................258 ..........................................................................................................................264 Route Advertisement..........Of JXSE..........................................................................258 Security.................................................................................................................................................................................258 Cache Pollution...........................................................................................................................259 Conclusion.........................................................................................................256 Code Examples.................258 JXTA vs....................................................................................262 Module Specification Advertisement ...................................................................................................................................................................................................................................................................................264 Access Point Advertisement.....................................263 Pipe Advertisement..............................................................................................................................................264 Index.........................................................261 Advertisement Attributes...................................................... OSGi.........................

this book contains code examples using the most recent features of JXSE. • System and network administrators – The JXTA technology is abstract in its concepts. step-by-step. how to take advantage of it. These were designed to be as didactic as possible. This book explains how administrators can improve the overall performance of JX- TA-based applications using an adequate configuration of their systems. this book will help keep you up-to-date with the recent evolution of the JXTA implementation.Who Should Read This Book? This book is intended for: • JXTA early adopters – If you are one of those who adopted JXTA since its inception. to facilit- ate the learning. the Java implementation of JXTA. NATs and proxies bound- aries. together with a lot of technical lan- guage. that is. or on your mobile phone and hand-held devices. to develop your own P2P applica- tions. Contrary to many books published earlier. You may even have used them for chatting. Nearly all imple- mentations of JXTA require mechanisms to overcome firewalls. in order to design JXTA-based P2P applications. phoning over the Internet. including those delivered as part of release 2. This book explains the origin of P2P and demystifies the un- deserved negative publicity it received at the beginning of the decade. that a functional analyst or a software architect needs to understand. making it hard to understand by everyone. • Managers and decision makers – If you are a manager or a decision maker. without optimization.14 . • Functional analysts and software architects – This book covers all the JXTA concepts (in- cluding their usage). It contains several basic code examples explaining how to use JXTA. and without com- promising security policies.6. although TCP/IP and HTTP are the most common. you may have heard about peer-to-peer technologies. You will be able to take inspiration from these building blocks for your own software implementations. • Software developers – This book will explain altogether the basic concepts of JXTA and how to use JXSE. The official JXTA specification document contains several abstract terms referencing each other. Security and control access issues to copyright Foreword Who Should Read This Book? . It describes the be- nefits of P2P. This book is solving this entanglement by using many metaphors from the real world. Many transportation protocols can be imple- mented with JXTA. and would like to know more about them. but it relies heavily on network transportation.

TCP/IP and HTTP. it can be used as a base to under- stand JXTA. System and network administrators should be aware of how TCP/IP.net/ for technical details. The code examples provided in this book are relying on version 2.5 (or a higher version). Developers willing to implement the JXTA protocols will have to refer to the official specification documentation available online at https://jxta-spec. in gen- eral. Foreword Prerequisites . NATs.6 of JXSE. routers and other types of network transportation systems operate in general. This book does not explain how to implement JXTA. Functional analysts and software architects need to know about XML. Managers and de- cision makers do not need to know more than general IT concepts. firewalls.java. Prerequisites This book assumes that software developers know about the Java programming language and concepts such as URI (Uniform Resource Identifiers). protected documents are also discussed here.dev. URL (Uniform Resource Locater) and URN (Uniform Resource Name). They should master the event firing and even listening mechanism. which requires JDK 1. proxies. However.15 .

15. unexpected loss of connections are not always detected and handled 'quickly' by JXSE. 16. 21. This a know issue. she automatically establishes contact with the third tribe. 22. Click OK. After 60 seconds. but after some time. Relatively quickly. Using JXSE Exploring Connectivity Issues . 56 Unfortunately. 18. Chihiro indicates that she is now connected to the other rendezvous still running.6 and has been postponed to a further release. The remaining rendezvous indicates that Chihiro is now connected to it. Press the OK button of the 'waiting for peers to connect' of the rendezvous to which Chi- hiro is connected. They check their rendezvous connections every 15 56 seconds . Chihiro). but they cannot establish contact with each other by land because of insurmountable mountains. The corresponding rendezvous displays the peer connected to it (i. 14. Chihiro displays another window indicating that she is ready to wait for another rendezvous connection again..e. Chihiro has heard about the Jack and the Aminah tribes. A window indicating that Chihiro is going to wait for 60 seconds to let the cache list of con- nected peers refresh is displayed. 17. This could not be accomplished for release 2. Solving it requires much refactoring in core code. click on OK on the screen indicating that the ren- dezvous is waiting for peers to connect. Metaphorically: The Jack tribe. Click OK and shut down the JXTA network for her.179 . Click OK. Stop the JXTA network for that rendezvous peer. We can notice that with a bit of patience Chihiro. She establishes contact with one of them. Back to the remaining rendezvous peer. that tribe decides to go hide in its cave. Connectivity Manager This book revision contains a new example explaining how to implement a connectivity manager. who was connected to one of its seed rendez- vous. the Aminah tribe and the Chihiro tribe are all living on the same big island. 13. Click OK. has managed to reconnect to another rendezvous seed when her initial rendezvous went down. Go back to back to Chihiro and click OK of the windows indicating that she is waiting for the shutdown of the rendezvous peer. 20. Click OK and shut down the JXTA network for the remaining peer. 19. This is performed automatically by JXSE. Edge peers try to maintain contact with at least and at most one rendezvous peer over time. Since Chihiro does not want to be alone.

The Relay The following is the code used for Robert.getBytes()). A possibility to enable TCP and HTTP communica- tion or not is provided.It is made of 5 java classes.. Name_RELAY. public class Relay_Robert { // Static public static final String Name_RELAY = "RELAY".separator") + Name_RELAY). public static final File ConfigurationFile_RELAY = new File(". but we will not include all code here: • ConnectivityMonitor – This is a frame displaying the connectivity status of peers.180 . public static final int HttpPort_RELAY = 9900. • Relay_Robert – A simple RELAY peer. a relay peer: ." + System. • Edge_Gina – A simple EDGE peer.getProperty("file.. Robert. • RendezVous_Mya – A simple RENDEZVOUS peer. public static final PeerID PID_RELAY = IDFactory. • DelayedJxtaNetworkStopper – Allows an asynchronous stop of the JXTA network.defaultNetPeerGroupID. public static final int TcpPort_RELAY = 9715. public static void main(String[] args) { try { Using JXSE Exploring Connectivity Issues .newPeerID(PeerGroupID.

println(Ex.181 . // Removing any existing configuration? NetworkManager. // Starting the connectivity monitor new ConnectivityMonitor(NetPeerGroup). Using JXSE Exploring Connectivity Issues . MyNetworkConfigurator. ConfigurationFile_RELAY.toString()). Multicasting is disabled.setTcpOutgoing(true). The network manager instance and corresponding network configurator are created.toString()).toURI()). // Retrieving the network configurator NetworkConfigurator MyNetworkConfigurator = MyNetworkManager. 0.setTcpPort(TcpPort_RELAY). // Starting the JXTA network PeerGroup NetPeerGroup = MyNetworkManager.SECONDS).RELAY.TheExecutor. A peer ID is set.setHttpEnabled(true). "Click to stop " + Name_RELAY. // Stopping the network asynchronously ConnectivityMonitor.startNetwork().setHttpOutgoing(true). Any existing configuration is deleted. // Creation of the network manager final NetworkManager MyNetworkManager = new NetworkManager( NetworkManager.RecursiveDelete(ConfigurationFile_RELAY). 2. // Setting Configuration MyNetworkConfigurator. 3.setTcpIncoming(true). MyNetworkConfigurator.ConfigMode. // Setting the Peer ID MyNetworkConfigurator.setTcpEnabled(true).err.err. MyNetworkConfigurator. 4. } } } Robert the Relay 1. MyNetworkConfigurator.setPeerID(PID_RELAY).schedule( new DelayedJxtaNetworkStopper( MyNetworkManager.setUseMulticast(false). MyNetworkConfigurator.getConfigurator().println(Ex.setHttpPort(HttpPort_RELAY). Name_RELAY. TimeUnit. "Stop"). while TCP and HTTP communication are enabled (we will explain why later). } catch (IOException Ex) { System. } catch (PeerGroupException Ex) { System. MyNetworkConfigurator. MyNetworkConfigurator.setHttpIncoming(true). MyNetworkConfigurator.

you must use HTTP and specify a relay node“. 58 An edge expects availability of TCP to connect to a rendezvous. This is not correct. Edge peers loop through their seeds of relay to try to maintain a permanent connection to their a relay peer. Mya and Gina. In this case. Otherwise. it is mentioned that “If you are located behind a firewall or NAT. Using JXSE Exploring Connectivity Issues . Many corporations only allow outbound HTTP traffic and block other ports and TCP traffic. Relay Connectivity 57 A connection to a relay peer can be established either via TCP or HTTP . • Peers on the same LAN do not need rendezvous to connect if they all have multicasting enabled. make it an adhoc to operate better . It will start the JXTA network. By using Robert. 57 In version 2. 6. • A relay peer should have either TCP incoming or HTTP incoming allowed. An asynchronous task is created to asynchronously stop the JXTA network.5 of the Programmer's Guide.182 . Summary The following table indicates which type of communication should be enabled according to the connection mode: Configuration ADHOC EDGE RENDEZVOUS RELAY TCP outgoing Not required Preferably Yes If possible TCP incoming Not required Not essential Yes Required HTTP outgoing Not required Preferably No required Not required HTTP incoming Not required Not essential Not required Required Multicasting Required Preferably Preferably If possible • It does not make sense to configure an edge with no outgoing communication enabled. HTTP becomes necessary. The connectivity monitor frame is set and started. 58 • If an edge is configured only with multicasting. one can test various connectivity scenarios with the connectivity manager. One may wonder when HTTP communication would be needed if TCP can be used by peers hav- ing a private address. This can be checked with edge Gina by enabling/disabling TCP and HTTP communication and by using Robert and Mya. edge peers will not be able to connect to it. to connect to relay peers. 5.