Add a peer to the channel

@param peer        The Peer to add.
@param peerOptions see {@link PeerRole}
@return Channel The current channel added.
@throws InvalidArgumentException
547579
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;
    }
401814
public static com.liferay.commerce.product.model.CPOption addCPOption(
		com.liferay.commerce.product.model.CPOption cpOption) {
		return getService().addCPOption(cpOption);
	}
412339
public void setChildChannelOptions(final Map<ChannelOption, Object> channelOptions) {
        this.childChannelOptions = channelOptions == null ? Collections.<ChannelOption, Object> emptyMap()
            : channelOptions;
    }
991103
public T tap(PointOption tapOptions) {
        ActionParameter action = new ActionParameter("tap", tapOptions);
        parameterBuilder.add(action);
        return (T) this;
    }
776275
public <T> AioServer setOption(SocketOption<T> name, T value) throws IOException {
		this.channel.setOption(name, value);
		return this;
	}
673996
public static base_responses add(nitro_service client, channel resources[]) throws Exception {
		base_responses result = null;
		if (resources != null && resources.length > 0) {
			channel addresources[] = new channel[resources.length];
			for (int i=0;i<resources.length;i++){
				addresources[i] = new channel();
				addresources[i].id = resources[i].id;
				addresources[i].ifnum = resources[i].ifnum;
				addresources[i].state = resources[i].state;
				addresources[i].mode = resources[i].mode;
				addresources[i].conndistr = resources[i].conndistr;
				addresources[i].macdistr = resources[i].macdistr;
				addresources[i].lamac = resources[i].lamac;
				addresources[i].speed = resources[i].speed;
				addresources[i].flowctl = resources[i].flowctl;
				addresources[i].hamonitor = resources[i].hamonitor;
				addresources[i].tagall = resources[i].tagall;
				addresources[i].trunk = resources[i].trunk;
				addresources[i].ifalias = resources[i].ifalias;
				addresources[i].throughput = resources[i].throughput;
				addresources[i].bandwidthhigh = resources[i].bandwidthhigh;
				addresources[i].bandwidthnormal = resources[i].bandwidthnormal;
			}
			result = add_bulk_request(client, addresources);
		}
		return result;
	}
587202
public void setPeerProperties(String name, Properties properties) throws InvalidArgumentException {
        setNodeProperties("Peer", name, peers, properties);
    }
864524
def add_candidate_peer_endpoints(self, peer_endpoints):
        
        if self._topology:
            self._topology.add_candidate_peer_endpoints(peer_endpoints)
        else:
            LOGGER.debug("Could not add peer endpoints to topology. "
                         "ConnectionManager does not exist.")
277011
public <T> NettyChannelBuilder withOption(ChannelOption<T> option, T value) {
    channelOptions.put(option, value);
    return this;
  }
396221
def AddConnectedPeer(self, peer):
        
        # if present
        self.RemoveFromQueue(peer.address)
        self.AddKnownAddress(peer.address)

        if len(self.Peers) > settings.CONNECTED_PEER_MAX:
            peer.Disconnect("Max connected peers reached", isDead=False)

        if peer not in self.Peers:
            self.Peers.append(peer)
        else:
            # either peer is already in the list and it has reconnected before it timed out on our side
            # or it's trying to connect multiple times
            # or we hit the max connected peer count
            self.RemoveKnownAddress(peer.address)
            peer.Disconnect()
721741
def _add_peernode(line):
    '''
    
    '''
    global lastpnodevolumes

    fields = line.strip().split()

    peernode = {}
    peernode["peernode name"] = fields[0]
    #Could be role or connection:
    peernode[fields[1].split(":")[0]] = fields[1].split(":")[1]
    peernode["peer volumes"] = []
    resource["peer nodes"].append(peernode)
    lastpnodevolumes = peernode["peer volumes"]
89536
public static void setChannelOptions(Channel channel, EndpointConfig config) {
        ChannelOptions options = channel.options();
        options.setOption(DIRECT_BUF, config.isSocketBufferDirect())
               .setOption(TCP_NODELAY, config.isSocketTcpNoDelay())
               .setOption(SO_KEEPALIVE, config.isSocketKeepAlive())
               .setOption(SO_SNDBUF, config.getSocketSendBufferSizeKb() * KILO_BYTE)
               .setOption(SO_RCVBUF, config.getSocketRcvBufferSizeKb() * KILO_BYTE)
               .setOption(SO_LINGER, config.getSocketLingerSeconds());
    }
879562
public Channel initialize() throws InvalidArgumentException, TransactionException {

        logger.debug(format("Channel %s initialize shutdown %b", name, shutdown));

        if (isInitialized()) {
            return this;
        }

        if (shutdown) {
            throw new InvalidArgumentException(format("Channel %s has been shutdown.", name));
        }

        if (isNullOrEmpty(name)) {

            throw new InvalidArgumentException("Can not initialize channel without a valid name.");

        }
        if (client == null) {
            throw new InvalidArgumentException("Can not initialize channel without a client object.");
        }

        userContextCheck(client.getUserContext());

        if (null == sdOrdererAddition) {

            setSDOrdererAddition(new SDOrdererDefaultAddition(getServiceDiscoveryProperties()));
        }

        if (null == sdPeerAddition) {

            setSDPeerAddition(new SDOPeerDefaultAddition(getServiceDiscoveryProperties()));

        }

        try {
            loadCACertificates(false);  // put all MSP certs into cryptoSuite if this fails here we'll try again later.
        } catch (Exception e) {
            logger.warn(format("Channel %s could not load peer CA certificates from any peers.", name));
        }
        Collection<Peer> serviceDiscoveryPeers = getServiceDiscoveryPeers();
        if (!serviceDiscoveryPeers.isEmpty()) {

            logger.trace("Starting service discovery.");

            this.serviceDiscovery = new ServiceDiscovery(this, serviceDiscoveryPeers, getTransactionContext());
            serviceDiscovery.fullNetworkDiscovery(true);
            serviceDiscovery.run();
            logger.trace("Completed. service discovery.");
        }

        try {

            logger.debug(format("Eventque started %s", "" + eventQueueThread));

            for (Peer peer : getEventingPeers()) {
                peer.initiateEventing(getTransactionContext(), getPeersOptions(peer));
            }

            transactionListenerProcessorHandle = registerTransactionListenerProcessor(); //Manage transactions.
            logger.debug(format("Channel %s registerTransactionListenerProcessor completed", name));

            if (serviceDiscovery != null) {
                chaincodeEventUpgradeListenerHandle = registerChaincodeEventListener(Pattern.compile("^lscc$"), Pattern.compile("^upgrade$"), (handle, blockEvent, chaincodeEvent) -> {
                    logger.debug(format("Channel %s got upgrade chaincode event", name));
                    if (!isShutdown() && isChaincodeUpgradeEvent(blockEvent.getBlockNumber())) {
                        getExecutorService().execute(() -> serviceDiscovery.fullNetworkDiscovery(true));
                    }
                });
            }

            startEventQue(); //Run the event for event messages from event hubs.
            logger.info(format("Channel %s eventThread started shutdown: %b  thread: %s ", toString(), shutdown, eventQueueThread == null ? "null" : eventQueueThread.getName()));

            this.initialized = true;

            logger.debug(format("Channel %s initialized", name));

            return this;

        } catch (Exception e) {
            TransactionException exp = new TransactionException(e);
            logger.error(exp.getMessage(), exp);
            throw exp;
        }

    }
850056
def add(peer)
      raise "Peer must have it's infoHash set." if ! peer.infoHash

      # Do not add if peer is already present by address
      if @peersByAddr.has_key?(byAddrKey(peer))
        @log.debug "Not adding peer #{peer} since it already exists by #{@peersById.has_key?(peer.trackerPeer.id) ? "id" : "addr"}."
        return
      end

      if peer.trackerPeer.id
        @peersById.pushToList(peer.trackerPeer.id, peer)
        
        # If id is null, this is probably a peer received from the tracker that has no ID.
      end

      @peersByAddr[byAddrKey(peer)] = peer

      @peersByInfoHash.pushToList(peer.infoHash, peer)
    end
582735
@SuppressWarnings("unchecked")
    public <T> Http2StreamChannelBootstrap option(ChannelOption<T> option, T value) {
        if (option == null) {
            throw new NullPointerException("option");
        }
        if (value == null) {
            synchronized (options) {
                options.remove(option);
            }
        } else {
            synchronized (options) {
                options.put(option, value);
            }
        }
        return this;
    }
897858
function addStreamToPeerConnection(stream, peerConnection) {
       if( peerConnection.addStream ) {
           var existingStreams = peerConnection.getLocalStreams();
           if (existingStreams.indexOf(stream) === -1) {
              peerConnection.addStream(stream);
           }
       }
       else {
          var existingTracks = peerConnection.getSenders();
          var tracks = stream.getAudioTracks();
          var i;
          for( i = 0; i < tracks.length; i++ ) {
            if (existingTracks.indexOf(tracks[i]) === -1) {
             peerConnection.addTrack( tracks[i]);
            }
          }
          tracks = stream.getVideoTracks();
          for( i = 0; i < tracks.length; i++ ) {
            if (existingTracks.indexOf(tracks[i]) === -1) {
             peerConnection.addTrack( tracks[i]);
            }
          }
       }
    }
644792
public Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
        return sendProposal(queryByChaincodeRequest, peers);
    }