com.google.bitcoin.protocols.channels
Class PaymentChannelServerListener

java.lang.Object
  extended by com.google.bitcoin.protocols.channels.PaymentChannelServerListener

public class PaymentChannelServerListener
extends Object

Implements a listening TCP server that can accept connections from payment channel clients, and invokes the provided event listeners when new channels are opened or payments arrive. This is the highest level class in the payment channels API. Internally, sends protobuf messages to/from a newly created PaymentChannelServer.


Nested Class Summary
static interface PaymentChannelServerListener.HandlerFactory
          A factory which generates connection-specific event handlers.
 
Constructor Summary
PaymentChannelServerListener(TransactionBroadcaster broadcaster, Wallet wallet, int timeoutSeconds, BigInteger minAcceptedChannelSize, PaymentChannelServerListener.HandlerFactory eventHandlerFactory)
          Sets up a new payment channel server which listens on the given port.
 
Method Summary
 void bindAndStart(int port)
          Binds to the given port and starts accepting new client connections.
 void close()
          Closes all client connections currently connected gracefully.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaymentChannelServerListener

public PaymentChannelServerListener(TransactionBroadcaster broadcaster,
                                    Wallet wallet,
                                    int timeoutSeconds,
                                    BigInteger minAcceptedChannelSize,
                                    PaymentChannelServerListener.HandlerFactory eventHandlerFactory)
                             throws IOException
Sets up a new payment channel server which listens on the given port.

Parameters:
broadcaster - The PeerGroup on which transactions will be broadcast - should have multiple connections.
wallet - The wallet which will be used to complete transactions
timeoutSeconds - The read timeout between messages. This should accommodate latency and client ECDSA signature operations.
minAcceptedChannelSize - The minimum amount of coins clients must lock in to create a channel. Clients which are unwilling or unable to lock in at least this value will immediately disconnect. For this reason, a fairly conservative value (in terms of average value spent on a channel) should generally be chosen.
eventHandlerFactory - A factory which generates event handlers which are created for each new connection
Throws:
IOException
Method Detail

bindAndStart

public void bindAndStart(int port)
                  throws Exception
Binds to the given port and starts accepting new client connections.

Throws:
Exception - If binding to the given port fails (eg SocketException: Permission denied for privileged ports)

close

public void close()

Closes all client connections currently connected gracefully.

Note that this does not settle the actual payment channels (and broadcast payment transactions), which must be done using the StoredPaymentChannelServerStates which manages the states for the associated wallet.



Copyright © 2014. All rights reserved.