public Channel addPeer ( Peer peer , PeerOptions peerOptions ) throws InvalidArgumentException { if ( shutdown ) { throw new InvalidArgumentException ( format ( "Channel %s has been shutdown." , name ) ) ; } if ( null == peer ) { throw new InvalidArgumentException ( "Peer is invalid can not be null." ) ; } if ( peer . getChannel ( ) != null && peer . getChannel ( ) != this ) { throw new InvalidArgumentException ( format ( "Peer already connected to channel %s" , peer . getChannel ( ) . getName ( ) ) ) ; } if ( null == peerOptions ) { throw new InvalidArgumentException ( "peerOptions is invalid can not be null." ) ; } logger . debug ( format ( "%s adding peer: %s, peerOptions: %s" , toString ( ) , peer , "" + peerOptions ) ) ; peer . setChannel ( this ) ; peers . add ( peer ) ; peerOptionsMap . put ( peer , peerOptions . clone ( ) ) ; peerEndpointMap . put ( peer . getEndpoint ( ) , peer ) ; if ( peerOptions . getPeerRoles ( ) . contains ( PeerRole . SERVICE_DISCOVERY ) ) { final Properties properties = peer . getProperties ( ) ; if ( ( properties == null ) || properties . isEmpty ( ) || ( isNullOrEmpty ( properties . getProperty ( "clientCertFile" ) ) && ! properties . containsKey ( "clientCertBytes" ) ) ) { TLSCertificateBuilder tlsCertificateBuilder = new TLSCertificateBuilder ( ) ; TLSCertificateKeyPair tlsCertificateKeyPair = tlsCertificateBuilder . clientCert ( ) ; peer . setTLSCertificateKeyPair ( tlsCertificateKeyPair ) ; } discoveryEndpoints . add ( peer . getEndpoint ( ) ) ; } for ( Map . Entry < PeerRole , Set < Peer > > peerRole : peerRoleSetMap . entrySet ( ) ) { if ( peerOptions . getPeerRoles ( ) . contains ( peerRole . getKey ( ) ) ) { peerRole . getValue ( ) . add ( peer ) ; } } if ( isInitialized ( ) && peerOptions . getPeerRoles ( ) . contains ( PeerRole . EVENT_SOURCE ) ) { try { peer . initiateEventing ( getTransactionContext ( ) , getPeersOptions ( peer ) ) ; } catch ( TransactionException e ) { logger . error ( format ( "Error channel %s enabling eventing on peer %s" , toString ( ) , peer ) ) ; } } return this ; }
Add a peer to the channel