本文整理汇总了Java中com.subgraph.orchid.Router类的典型用法代码示例。如果您正苦于以下问题:Java Router类的具体用法?Java Router怎么用?Java Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Router类属于com.subgraph.orchid包,在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendIntroduce
import com.subgraph.orchid.Router; //导入依赖的package包/类
boolean sendIntroduce(TorPublicKey permanentKey, byte[] publicKeyBytes, byte[] rendezvousCookie, Router rendezvousRouter) {
final RelayCell introduceCell = introductionCircuit.createRelayCell(RelayCell.RELAY_COMMAND_INTRODUCE1, 0, introductionCircuit.getFinalCircuitNode());
final byte[] payload = createIntroductionPayload(rendezvousRouter, publicKeyBytes, rendezvousCookie, permanentKey);
final TorPublicKey serviceKey = introductionPoint.getServiceKey();
introduceCell.putByteArray(serviceKey.getFingerprint().getRawBytes());
introduceCell.putByteArray(payload);
introductionCircuit.sendRelayCell(introduceCell);
final RelayCell response = introductionCircuit.receiveRelayCell();
if(response == null) {
logger.fine("Timeout waiting for response to INTRODUCE1 cell");
return false;
} else if(response.getRelayCommand() != RelayCell.RELAY_COMMAND_INTRODUCE_ACK) {
logger.info("Unexpected relay cell type received waiting for response to INTRODUCE1 cell: "+ response.getRelayCommand());
return false;
} else if(response.cellBytesRemaining() == 0) {
return true;
} else {
logger.info("INTRODUCE_ACK indicates that introduction was not forwarded: "+ response.getByte());
return false;
}
}
示例2: receiveRelayResponse
import com.subgraph.orchid.Router; //导入依赖的package包/类
public RelayCell receiveRelayResponse(int expectedCommand, Router extendTarget) {
final RelayCell cell = circuit.receiveRelayCell();
if(cell == null) {
throw new TorException("Timeout building circuit");
}
final int command = cell.getRelayCommand();
if(command == RelayCell.RELAY_TRUNCATED) {
final int code = cell.getByte() & 0xFF;
final String msg = CellImpl.errorToDescription(code);
final String source = nodeToName(cell.getCircuitNode());
if(code == Cell.ERROR_PROTOCOL) {
logProtocolViolation(source, extendTarget);
}
throw new TorException("Error from ("+ source +") while extending to ("+ extendTarget.getNickname() + "): "+ msg);
} else if(command != expectedCommand) {
final String expected = RelayCellImpl.commandToDescription(expectedCommand);
final String received = RelayCellImpl.commandToDescription(command);
throw new TorException("Received incorrect extend response, expecting "+ expected + " but received "+ received);
} else {
return cell;
}
}
示例3: chooseRandomBridge
import com.subgraph.orchid.Router; //导入依赖的package包/类
BridgeRouter chooseRandomBridge(Set<Router> excluded) throws InterruptedException {
synchronized(lock) {
if(!bridgesInitialized && !bridgesInitializing) {
initializeBridges();
}
while(!bridgesInitialized && !hasCandidates(excluded)) {
lock.wait();
}
final List<BridgeRouter> candidates = getCandidates(excluded);
if(candidates.isEmpty()) {
logger.warning("Bridges enabled but no usable bridges configured");
return null;
}
return candidates.get(random.nextInt(candidates.size()));
}
}
示例4: selectDirectoriesAtIndex
import com.subgraph.orchid.Router; //导入依赖的package包/类
private List<Router> selectDirectoriesAtIndex(int idx) {
if(idx < 0 || idx >= hsDirectories.size()) {
throw new IllegalArgumentException("idx = "+ idx);
}
if(hsDirectories.size() < DIR_CLUSTER_SZ) {
throw new IllegalStateException();
}
final List<Router> dirs = new ArrayList<Router>(DIR_CLUSTER_SZ);
for(int i = 0; i < DIR_CLUSTER_SZ; i++) {
dirs.add(hsDirectories.get(idx));
idx += 1;
if(idx == hsDirectories.size()) {
idx = 0;
}
}
randomShuffle(dirs);
return dirs;
}
示例5: checkMinimumRouterInfo
import com.subgraph.orchid.Router; //导入依赖的package包/类
private synchronized void checkMinimumRouterInfo() {
if(currentConsensus == null || !currentConsensus.isLive()) {
needRecalculateMinimumRouterInfo = true;
haveMinimumRouterInfo = false;
return;
}
int routerCount = 0;
int descriptorCount = 0;
for(Router r: routersByIdentity.values()) {
routerCount++;
if(!r.isDescriptorDownloadable())
descriptorCount++;
}
needRecalculateMinimumRouterInfo = false;
haveMinimumRouterInfo = (descriptorCount * 4 > routerCount);
}
示例6: filterForExitTargets
import com.subgraph.orchid.Router; //导入依赖的package包/类
private List<Router> filterForExitTargets(List<Router> routers, List<ExitTarget> exitTargets) {
int bestSupport = 0;
if(exitTargets.isEmpty()) {
return routers;
}
final int[] nSupport = new int[routers.size()];
for(int i = 0; i < routers.size(); i++) {
final Router r = routers.get(i);
nSupport[i] = countTargetSupport(r, exitTargets);
if(nSupport[i] > bestSupport) {
bestSupport = nSupport[i];
}
}
if(bestSupport == 0) {
return routers;
}
final List<Router> results = new ArrayList<Router>();
for(int i = 0; i < routers.size(); i++) {
if(nSupport[i] == bestSupport) {
results.add(routers.get(i));
}
}
return results;
}
示例7: ConnectionImpl
import com.subgraph.orchid.Router; //导入依赖的package包/类
public ConnectionImpl(TorConfig config, SSLSocket socket, Router router, TorInitializationTracker tracker, boolean isDirectoryConnection) {
this.config = config;
this.socket = socket;
this.router = router;
this.circuitMap = new HashMap<Integer, Circuit>();
this.readCellsThread = new Thread(createReadCellsRunnable());
this.readCellsThread.setDaemon(true);
this.connectionControlCells = new LinkedBlockingQueue<Cell>();
this.initializationTracker = tracker;
this.isDirectoryConnection = isDirectoryConnection;
initializeCurrentCircuitId();
}
示例8: chooseRandomNode
import com.subgraph.orchid.Router; //导入依赖的package包/类
/**
*
* @param rule
* @param routerFilter
* @return The chosen router or 'null' if no suitable router is available.
*/
public Router chooseRandomNode(WeightRule rule, RouterFilter routerFilter) {
final List<Router> candidates = getFilteredRouters(routerFilter, true);
final Router choice = chooseByBandwidth(candidates, rule);
if(choice == null) {
// try again with more permissive flags
return null;
}
return choice;
}
示例9: verifyIdentityKey
import com.subgraph.orchid.Router; //导入依赖的package包/类
protected void verifyIdentityKey(PublicKey publicKey) throws ConnectionHandshakeException {
if(!(publicKey instanceof RSAPublicKey)) {
throw new ConnectionHandshakeException("Identity certificate public key is not an RSA key as expected");
}
final TorPublicKey identityKey = new TorPublicKey((RSAPublicKey)publicKey);
final Router router = connection.getRouter();
if((router instanceof BridgeRouter) && (router.getIdentityHash() == null)) {
logger.info("Setting Bridge fingerprint from connection handshake for "+ router);
((BridgeRouter) router).setIdentity(identityKey.getFingerprint());
} else if(!identityKey.getFingerprint().equals(router.getIdentityHash())) {
throw new ConnectionHandshakeException("Router identity does not match certificate key");
}
}
示例10: extendTo
import com.subgraph.orchid.Router; //导入依赖的package包/类
CircuitNode extendTo(Router targetRouter) {
if(circuit.getCircuitLength() == 0) {
throw new TorException("Cannot EXTEND an empty circuit");
}
if(useNtor(targetRouter)) {
final NTorCircuitExtender nce = new NTorCircuitExtender(this, targetRouter);
return nce.extendTo();
} else {
final TapCircuitExtender tce = new TapCircuitExtender(this, targetRouter);
return tce.extendTo();
}
}
示例11: getRouterListByNames
import com.subgraph.orchid.Router; //导入依赖的package包/类
public List<Router> getRouterListByNames(List<String> names) {
waitUntilLoaded();
final List<Router> routers = new ArrayList<Router>();
for(String n: names) {
final Router r = getRouterByName(n);
if(r == null)
throw new TorException("Could not find router named: "+ n);
routers.add(r);
}
return routers;
}
示例12: getFutureFor
import com.subgraph.orchid.Router; //导入依赖的package包/类
private Future<ConnectionImpl> getFutureFor(Router router, boolean isDirectoryConnection) {
Future<ConnectionImpl> f = activeConnections.get(router);
if(f != null) {
return f;
}
return createFutureForIfAbsent(router, isDirectoryConnection);
}
示例13: getPeers
import com.subgraph.orchid.Router; //导入依赖的package包/类
@Override
public InetSocketAddress[] getPeers(long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
if (hostNames == null)
throw new PeerDiscoveryException("Unable to find any peers via DNS");
Set<Router> routers = Sets.newHashSet();
ArrayList<ExitTarget> dummyTargets = Lists.newArrayList();
// Collect exit nodes until we have enough
while (routers.size() < ROUTER_LOOKUP_COUNT) {
Router router = pathChooser.chooseExitNodeForTargets(dummyTargets);
routers.add(router);
}
try {
List<Circuit> circuits =
getCircuits(torClient.getConfig().getCircuitBuildTimeout(), TimeUnit.MILLISECONDS, routers);
if (circuits.isEmpty())
throw new PeerDiscoveryException("Failed to open any circuit within " +
String.valueOf(timeoutValue) + " " + timeoutUnit);
Collection<InetSocketAddress> addresses = lookupAddresses(timeoutValue, timeoutUnit, circuits);
if (addresses.size() < MINIMUM_ROUTER_COUNT)
throw new PeerDiscoveryException("Unable to find enough peers via Tor - got " + addresses.size());
ArrayList<InetSocketAddress> addressList = Lists.newArrayList();
addressList.addAll(addresses);
Collections.shuffle(addressList);
return addressList.toArray(new InetSocketAddress[addressList.size()]);
} catch (InterruptedException e) {
throw new PeerDiscoveryException(e);
}
}
示例14: filter
import com.subgraph.orchid.Router; //导入依赖的package包/类
public boolean filter(Router router) {
for(RouterFilter f: filterList) {
if(f.filter(router)) {
return true;
}
}
return false;
}
示例15: getCandidates
import com.subgraph.orchid.Router; //导入依赖的package包/类
private List<BridgeRouter> getCandidates(Set<Router> excluded) {
if(bridgeRouters.isEmpty()) {
return Collections.emptyList();
}
final List<BridgeRouter> candidates = new ArrayList<BridgeRouter>(bridgeRouters.size());
for(BridgeRouter br: bridgeRouters) {
if(!excluded.contains(br)) {
candidates.add(br);
}
}
return candidates;
}