资源简介
用peersim实现的pastry算法,可以在eclipse下运行
代码片段和文件信息
package peersim.pastry;
import peersim.core.CommonState;
import peersim.config.Configuration;
import peersim.core.Network;
import java.math.BigInteger;
//______________________________________________________________________________________________
/**
* This control initializes the whole network (that was already created by peersim) by assigning a
* unique NodeId randomly generated to every node (it does nothing else).
* title: MSPASTRY
*
* Description: MsPastry implementation for PeerSim
*
* Copyright: Copyright (c) 2007
*
* Company: The Pastry Group
*
* @author Elisa Bisoffi Manuel Cortella
* @version 1.0
*/
public class CustomDistribution implements peersim.core.Control {
//______________________________________________________________________________________________
private static final String PAR_PROT = “protocol“;
private int protocolID;
private UniformRandomGenerator urg;
//______________________________________________________________________________________________
public CustomDistribution(String prefix) {
protocolID = Configuration.getPid(prefix + “.“ + PAR_PROT);
urg = new UniformRandomGenerator(MSPastryCommonConfig.BITS CommonState.r);
}
//______________________________________________________________________________________________
/**
* Scan over the nodes in the network and assign a randomly generated NodeId in the space
* 0..2^BITS where BITS is a parameter from the pastry protocol (usually 128)
* @return boolean always false
*/
public boolean execute() {
BigInteger tmp;
for (int i = 0; i < Network.size(); ++i) {
tmp = urg.generate();
((MSPastryProtocol)(Network.get(i).getProtocol(protocolID))).setNodeId(tmp);
}
return false;
}
//______________________________________________________________________________________________
} // End of class
- 上一篇:3.5mm耳机插座封装库
- 下一篇:基于n-gram的文本分类
评论
共有 条评论