• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ProtobufParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.bitcoin.net.ProtobufParser的典型用法代码示例。如果您正苦于以下问题:Java ProtobufParser类的具体用法?Java ProtobufParser怎么用?Java ProtobufParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ProtobufParser类属于com.google.bitcoin.net包,在下文中一共展示了ProtobufParser类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: PaymentChannelClientConnection

import com.google.bitcoin.net.ProtobufParser; //导入依赖的package包/类
/**
 * Attempts to open a new connection to and open a payment channel with the given host and port, blocking until the
 * connection is open
 *
 * @param server The host/port pair where the server is listening.
 * @param timeoutSeconds The connection timeout and read timeout during initialization. This should be large enough
 *                       to accommodate ECDSA signature operations and network latency.
 * @param wallet The wallet which will be paid from, and where completed transactions will be committed.
 *               Must already have a {@link StoredPaymentChannelClientStates} object in its extensions set.
 * @param myKey A freshly generated keypair used for the multisig contract and refund output.
 * @param maxValue The maximum value this channel is allowed to request
 * @param serverId A unique ID which is used to attempt reopening of an existing channel.
 *                 This must be unique to the server, and, if your application is exposing payment channels to some
 *                 API, this should also probably encompass some caller UID to avoid applications opening channels
 *                 which were created by others.
 *
 * @throws IOException if there's an issue using the network.
 * @throws ValueOutOfRangeException if the balance of wallet is lower than maxValue.
 */
public PaymentChannelClientConnection(InetSocketAddress server, int timeoutSeconds, Wallet wallet, ECKey myKey,
                                      BigInteger maxValue, String serverId) throws IOException, ValueOutOfRangeException {
    // Glue the object which vends/ingests protobuf messages in order to manage state to the network object which
    // reads/writes them to the wire in length prefixed form.
    channelClient = new PaymentChannelClient(wallet, myKey, maxValue, Sha256Hash.create(serverId.getBytes()),
          new PaymentChannelClient.ClientConnection() {
        @Override
        public void sendToServer(Protos.TwoWayChannelMessage msg) {
            wireParser.write(msg);
        }

        @Override
        public void destroyConnection(PaymentChannelCloseException.CloseReason reason) {
            channelOpenFuture.setException(new PaymentChannelCloseException("Payment channel client requested that the connection be closed: " + reason, reason));
            wireParser.closeConnection();
        }

        @Override
        public void channelOpen(boolean wasInitiated) {
            wireParser.setSocketTimeout(0);
            // Inform the API user that we're done and ready to roll.
            channelOpenFuture.set(PaymentChannelClientConnection.this);
        }
    });

    // And glue back in the opposite direction - network to the channelClient.
    wireParser = new ProtobufParser<Protos.TwoWayChannelMessage>(new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
        @Override
        public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
            try {
                channelClient.receiveMessage(msg);
            } catch (InsufficientMoneyException e) {
                // We should only get this exception during INITIATE, so channelOpen wasn't called yet.
                channelOpenFuture.setException(e);
            }
        }

        @Override
        public void connectionOpen(ProtobufParser handler) {
            channelClient.connectionOpen();
        }

        @Override
        public void connectionClosed(ProtobufParser handler) {
            channelClient.connectionClosed();
            channelOpenFuture.setException(new PaymentChannelCloseException("The TCP socket died",
                    PaymentChannelCloseException.CloseReason.CONNECTION_CLOSED));
        }
    }, Protos.TwoWayChannelMessage.getDefaultInstance(), Short.MAX_VALUE, timeoutSeconds*1000);

    // Initiate the outbound network connection. We don't need to keep this around. The wireParser object will handle
    // things from here on out.
    new NioClient(server, wireParser, timeoutSeconds * 1000);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:74,代码来源:PaymentChannelClientConnection.java


示例2: ServerHandler

import com.google.bitcoin.net.ProtobufParser; //导入依赖的package包/类
public ServerHandler(final SocketAddress address, final int timeoutSeconds) {
    paymentChannelManager = new PaymentChannelServer(broadcaster, wallet, minAcceptedChannelSize, new PaymentChannelServer.ServerConnection() {
        @Override public void sendToClient(Protos.TwoWayChannelMessage msg) {
            socketProtobufHandler.write(msg);
        }

        @Override public void destroyConnection(PaymentChannelCloseException.CloseReason reason) {
            if (closeReason != null)
                closeReason = reason;
            socketProtobufHandler.closeConnection();
        }

        @Override public void channelOpen(Sha256Hash contractHash) {
            socketProtobufHandler.setSocketTimeout(0);
            eventHandler.channelOpen(contractHash);
        }

        @Override public void paymentIncrease(BigInteger by, BigInteger to) {
            eventHandler.paymentIncrease(by, to);
        }
    });

    protobufHandlerListener = new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
        @Override
        public synchronized void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
            paymentChannelManager.receiveMessage(msg);
        }

        @Override
        public synchronized void connectionClosed(ProtobufParser handler) {
            paymentChannelManager.connectionClosed();
            if (closeReason != null)
                eventHandler.channelClosed(closeReason);
            else
                eventHandler.channelClosed(PaymentChannelCloseException.CloseReason.CONNECTION_CLOSED);
            eventHandler.setConnectionChannel(null);
        }

        @Override
        public synchronized void connectionOpen(ProtobufParser handler) {
            ServerConnectionEventHandler eventHandler = eventHandlerFactory.onNewConnection(address);
            if (eventHandler == null)
                handler.closeConnection();
            else {
                ServerHandler.this.eventHandler = eventHandler;
                paymentChannelManager.connectionOpen();
            }
        }
    };

    socketProtobufHandler = new ProtobufParser<Protos.TwoWayChannelMessage>
            (protobufHandlerListener, Protos.TwoWayChannelMessage.getDefaultInstance(), Short.MAX_VALUE, timeoutSeconds*1000);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:54,代码来源:PaymentChannelServerListener.java


示例3: setConnectionChannel

import com.google.bitcoin.net.ProtobufParser; //导入依赖的package包/类
synchronized void setConnectionChannel(@Nullable ProtobufParser connectionChannel) { this.connectionChannel = connectionChannel; } 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:2,代码来源:ServerConnectionEventHandler.java



注:本文中的com.google.bitcoin.net.ProtobufParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Context类代码示例发布时间:2022-05-22
下一篇:
Java Server类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap