当前位置: 首页>>代码示例>>Java>>正文


Java DHTStatus类代码示例

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


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

示例1: init

import lbms.plugins.mldht.kad.DHTStatus; //导入依赖的package包/类
public void init() throws Exception {
    DHT.setLogLevel(LogLevel.Debug);

    initialize();
    dht = DHT.getDHT(DHTtype.IPV4_DHT);
    dht.addIndexingLinstener(new DHTIndexingListener() {
        @Override
        public List<PeerAddressDBItem> incomingPeersRequest(Key infoHash, InetAddress sourceAddress, Key nodeID) {
            logger.info("Incoming peer request: " + infoHash);
            return Collections.emptyList();
        }
    });
    
    dht.addStatusListener(new DHTStatusListener() {
        @Override
        public void statusChanged(DHTStatus newStatus, DHTStatus oldStatus) {
            logger.info("DHT Status changed: " + newStatus);
        }
    });
    
    dht.start(getConfiguration(), getServerListener());
    Thread.sleep(10000);

    logger.info("Servers: " + dht.getServers());
    
    InetSocketAddress peer = null;
    System.out.println(dht.getNode().getNumEntriesInRoutingTable());
    for (RoutingTableEntry entry : dht.getNode().getBuckets()) {
        for (KBucketEntry bucketEntry : entry.getBucket().getEntries()) {
            if (bucketEntry.getAddress() != null) {
                peer = bucketEntry.getAddress();
            }
        }
    }

    dht.getRandomServer().ping(peer);

    // TODO how to get response? We are notified in the server listener that there is a response, but not what
    // it is

    Thread.sleep(10000);

    System.out.println("-----sending get peers request-----");
    GetPeersRequest request =
            new GetPeersRequest(new Key(hexStringToByteArray("64DD3835A88FE9BE6826B4B701AD35177ABD376C")));
    request.setID(dht.getRandomServer().getDerivedID());
    request.setDestination(peer);
    dht.getRandomServer().sendMessage(request);

    Thread.sleep(10000);
    System.out.println(dht.getRandomServer().getNumReceived());
    System.out.println(dht.getNode().getNumEntriesInRoutingTable());
}
 
开发者ID:Glamdring,项目名称:scientific-publishing,代码行数:54,代码来源:DHTService.java


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