本文整理汇总了Java中net.tomp2p.peers.Number160.createHash方法的典型用法代码示例。如果您正苦于以下问题:Java Number160.createHash方法的具体用法?Java Number160.createHash怎么用?Java Number160.createHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.tomp2p.peers.Number160
的用法示例。
在下文中一共展示了Number160.createHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDir
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Override
public void createDir(String path) throws ClassNotFoundException, FsException, IOException {
Path subPaths = Paths.get(path);
int pathLength = subPaths.getNameCount();
if (pathLength == 0) {
throw new NotADirectoryException("Don't create a root node like that! Path: "+path);
}
Directory parentEntry = getDirectory(subPaths.getParent().toString());
if (parentEntry.getChild(subPaths.getFileName().toString()) != null) {
throw new FileExistsException(path);
}
Number160 newKey = Number160.createHash(UUID.randomUUID().hashCode());
Directory newDir = new Directory(newKey, subPaths.getFileName().toString());
helper.addNewEntry(parentEntry, newDir);
}
示例2: createFile
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Override
public void createFile(String path) throws ClassNotFoundException, FsException, IOException {
Path subPaths = Paths.get(path);
int pathLength = subPaths.getNameCount();
if (pathLength == 0) {
throw new NoSuchFileOrDirectoryException("Can not create such file");
}
Directory parentEntry = getDirectory(subPaths.getParent().toString());
if (parentEntry.getChild(subPaths.getFileName().toString()) != null) {
throw new FileExistsException(path);
}
Number160 newKey = Number160.createHash(UUID.randomUUID().hashCode());
File newFile = new File (newKey, subPaths.getFileName().toString());
//this is new locking logic, due to fuse constraints we have to associate a file creation with the respective owner
newFile.setDirtyBit(true);
newFile.setModifierPeer(peer.peerID());
helper.addNewEntry(parentEntry, newFile);
}
示例3: getPeerAddress
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public PeerAddress getPeerAddress(String player) {
if (getId().equals(player)) {
return peer.getPeerAddress();
} else {
Number160 id = Number160.createHash(player);
PeerMap pm = peer.getPeerBean().getPeerMap();
for (PeerAddress pa : pm.getAll()) {
if (pa.getID().equals(id)) {
return pa;
}
}
return null;
}
}
示例4: list
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
/**
* Lists friends that are stored in the DHT.
*
* @param nickName
* The nickname as the location key, where the data is stored
* @throws IOException .
* @throws ClassNotFoundException .
*/
public void list(final String nickName) throws IOException, ClassNotFoundException {
Number160 key = Number160.createHash(nickName);
FutureTracker futureTracker = peer.getTracker(key).start();
// now we know which peer has this data, and we also know what other things this peer has
futureTracker.awaitUninterruptibly();
Collection<TrackerData> trackerDatas = futureTracker.getTrackers();
for (TrackerData trackerData : trackerDatas) {
String[] attachement = (String[]) Utils.decodeJavaObject(trackerData.getAttachement(), 0,
trackerData.getAttachement().length);
for (String s1 : attachement) {
System.out.println("this peers' (" + nickName + ") friend:" + s1);
}
}
System.out.println("Tracker reports that " + trackerDatas.size() + " peer(s) are his friends");
}
示例5: testRenamingChild
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Test
public void testRenamingChild() {
String oldName = "child";
String newName = "childWithNewName";
Number160 childID = Number160.createHash(37829);
Directory child = new Directory(childID, oldName);
root.addChild(child.getEntryName(), child.getID(), child.getType());
root.renameChild(oldName, newName);
assertEquals(childID, root.getChild(newName));
}
示例6: FileDep
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
FileDep(String fileName, String fileLocation, String dhtKey, boolean sticky, int checkSum) {
this.fileName = fileName;
this.fileLocation = fileLocation;
this.dhtKey = Number160.createHash(dhtKey);
this.sticky = sticky;
this.checkSum = checkSum;
}
示例7: main
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
/**
* Generates a suitable json-String to put in a file, used for debugging
* @param args empty array
*/
public static void main(String[] args){
FileDep rawIndata = new FileDep("2_2000.raw", "resources", Number160.createHash("Primes_2_2000"), false, 25);
List<FileDep> deps = new ArrayList<>();
deps.add(rawIndata);
FileDep algorithm = new FileDep("Prime.hs", "code", Number160.createHash("Primes_algorithms"), true, 500);
TaskMeta taskMetaTest = new TaskMeta("PrimeTask_01", algorithm, deps);
System.out.println( new Gson().toJson(taskMetaTest));
}
示例8: createNr
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
/**
* Create a partial key with the first 64bit and fills the last 96bit with nr.
*
* @param key1
* The key to fill the first 64bits
* @param nr
* The number to fill the last 96bits
* @return The complete key
*/
//CHECKSTYLE:OFF
private static Number160 createNr(final String key1, final int nr) {
Number160 firstKey = Number160.createHash(key1);
int[] val = firstKey.toIntArray();
val[0] = val[0] ^ val[4] ^ val[3] ^ val[2];
val[1] = val[1] ^ val[4] ^ val[3] ^ val[2];
val[2] = nr;
val[3] = nr;
val[4] = nr;
return new Number160(val);
}
示例9: removeFromToTest4
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Test
public void removeFromToTest4() throws IOException, ClassNotFoundException {
PeerDHT p1 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(1)).ports(5000).start()).start();
PeerDHT p2 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(2)).masterPeer(p1.peer()).start()).start();
p2.peer().bootstrap().peerAddress(p1.peerAddress()).start().awaitUninterruptibly();
p1.peer().bootstrap().peerAddress(p2.peerAddress()).start().awaitUninterruptibly();
Number160 lKey = Number160.createHash("location");
Number160 dKey = Number160.createHash("domain");
Number160 cKey = Number160.createHash("content");
H2HTestData data = new H2HTestData(randomString());
try {
p2.put(lKey).data(cKey, new Data(data)).domainKey(dKey).start().awaitUninterruptibly();
FutureRemove futureRemove = p1.remove(lKey).from(new Number640(lKey, dKey, cKey, Number160.ZERO))
.to(new Number640(lKey, dKey, cKey, Number160.MAX_VALUE)).start();
futureRemove.awaitUninterruptibly();
FutureDigest futureDigest = p1.digest(lKey).from(new Number640(lKey, dKey, cKey, Number160.ZERO))
.to(new Number640(lKey, dKey, cKey, Number160.MAX_VALUE)).start();
futureDigest.awaitUninterruptibly();
// should be empty
assertTrue(futureDigest.digest().keyDigest().isEmpty());
} finally {
p1.shutdown().awaitUninterruptibly();
p2.shutdown().awaitUninterruptibly();
}
}
示例10: get
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
private FutureDHT get( String key, String domain, String content )
{
Number160 locationKey = Number160.createHash( key );
Number160 domainKey = Number160.createHash( domain );
Number160 contentKey = Number160.createHash( content );
return peer.get( locationKey ).setDomainKey( domainKey ).setContentKey( contentKey ).start();
}
示例11: setLocationKey
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
public Parameters setLocationKey(String locationKey) {
this.locationKey = locationKey;
this.lKey = Number160.createHash(locationKey);
return this;
}
示例12: setDomainKey
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
public Parameters setDomainKey(String domainKey) {
this.domainKey = domainKey;
this.dKey = Number160.createHash(domainKey);
return this;
}
示例13: setContentKey
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
public Parameters setContentKey(String contentKey) {
this.contentKey = contentKey;
this.cKey = Number160.createHash(contentKey);
return this;
}
示例14: getFromToTest1
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Test
public void getFromToTest1() throws IOException, ClassNotFoundException, InterruptedException {
PeerDHT p1 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(1)).ports(4838).start()).start();
PeerDHT p2 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(2)).masterPeer(p1.peer()).start()).start();
p2.peer().bootstrap().peerAddress(p1.peerAddress()).start().awaitUninterruptibly();
p1.peer().bootstrap().peerAddress(p2.peerAddress()).start().awaitUninterruptibly();
Number160 locationKey = Number160.createHash("location");
Number160 contentKey = Number160.createHash("content");
try {
List<H2HTestData> contents = new ArrayList<H2HTestData>();
int numberOfContent = 3;
for (int i = 0; i < numberOfContent; i++) {
H2HTestData data = new H2HTestData(randomString());
contents.add(data);
Data object = new Data(data);
if (i == 0) {
object.addBasedOn(Number160.ZERO);
} else {
object.addBasedOn(contents.get(i - 1).getVersionKey());
}
p2.put(locationKey).data(contentKey, object).versionKey(new Number160(i)).start().awaitUninterruptibly();
}
// get the last version
Number640 from = new Number640(locationKey, Number160.ZERO, contentKey, Number160.ZERO);
Number640 to = new Number640(locationKey, Number160.ZERO, contentKey, Number160.MAX_VALUE);
System.err.println("from: " + from);
System.err.println("to: " + to);
FutureGet future = p1.get(locationKey).from(from).to(to).descending().returnNr(1).start();
future.awaitUninterruptibly();
assertEquals(contents.get(numberOfContent - 1).getTestString(),
((H2HTestData) future.data().object()).getTestString());
} finally {
p1.shutdown().awaitUninterruptibly();
p2.shutdown().awaitUninterruptibly();
}
}
示例15: testBigStorePut
import net.tomp2p.peers.Number160; //导入方法依赖的package包/类
@Test
public void testBigStorePut() throws Exception {
StorageGeneric storeSender = new StorageMemory();
StorageGeneric storeRecv = new StorageMemory();
Peer sender = null;
Peer recv1 = null;
ChannelCreator cc = null;
try {
sender = new PeerMaker(new Number160("0x50")).p2pId(55).ports(2424).makeAndListen();
recv1 = new PeerMaker(new Number160("0x20")).p2pId(55).ports(8088).makeAndListen();
sender.getPeerBean().storage(storeSender);
StorageRPC smmSender = new StorageRPC(sender.getPeerBean(), sender.getConnectionBean());
recv1.getPeerBean().storage(storeRecv);
new StorageRPC(recv1.getPeerBean(), recv1.getConnectionBean());
Map<Number160, Data> tmp = new HashMap<Number160, Data>();
byte[] me1 = new byte[100];
byte[] me2 = new byte[10000];
tmp.put(new Number160(77), new Data(me1));
tmp.put(new Number160(88), new Data(me2));
FutureChannelCreator fcc = recv1.getConnectionBean().reservation().create(0, 1);
fcc.awaitUninterruptibly();
cc = fcc.getChannelCreator();
PutBuilder putBuilder = new PutBuilder(recv1, new Number160(33));
putBuilder.setDomainKey(Number160.createHash("test"));
DataMap dataMap = new DataMap(new Number160(33), Number160.createHash("test"), tmp);
putBuilder.setDataMapContent(tmp);
FutureResponse fr = smmSender.put(recv1.getPeerAddress(), putBuilder, cc);
fr.awaitUninterruptibly();
Assert.assertEquals(true, fr.isSuccess());
Keys keys = fr.getResponse().getKeys(0);
Utils.isSameSets(keys.keys(), dataMap.convertToMap480().keySet());
} finally {
if (cc != null) {
cc.shutdown().awaitListenersUninterruptibly();
}
if (sender != null) {
sender.shutdown().await();
}
if (recv1 != null) {
recv1.shutdown().await();
}
}
}