本文整理汇总了Java中com.subgraph.orchid.TorException类的典型用法代码示例。如果您正苦于以下问题:Java TorException类的具体用法?Java TorException怎么用?Java TorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TorException类属于com.subgraph.orchid包,在下文中一共展示了TorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: base32Encode
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public static String base32Encode(byte[] source, int offset, int length) {
final int nbits = length * 8;
if(nbits % 5 != 0)
throw new TorException("Base32 input length must be a multiple of 5 bits");
final int outlen = nbits / 5;
final StringBuffer outbuffer = new StringBuffer();
int bit = 0;
for(int i = 0; i < outlen; i++) {
int v = (source[bit / 8] & 0xFF) << 8;
if(bit + 5 < nbits) v += (source[bit / 8 + 1] & 0xFF);
int u = (v >> (11 - (bit % 8))) & 0x1F;
outbuffer.append(BASE32_CHARS.charAt(u));
bit += 5;
}
return outbuffer.toString();
}
示例2: base32Decode
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public static byte[] base32Decode(String source) {
int[] v = stringToIntVector(source);
int nbits = source.length() * 5;
if(nbits % 8 != 0)
throw new TorException("Base32 decoded array must be a muliple of 8 bits");
int outlen = nbits / 8;
byte[] outbytes = new byte[outlen];
int bit = 0;
for(int i = 0; i < outlen; i++) {
int bb = bit / 5;
outbytes[i] = (byte) decodeByte(bit, v[bb], v[bb + 1], v[bb + 2]);
bit += 8;
}
return outbytes;
}
示例3: parseBase64Data
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public byte[] parseBase64Data() {
final StringBuilder string = new StringBuilder(getItem());
switch(string.length() % 4) {
case 2:
string.append("==");
break;
case 3:
string.append("=");
break;
default:
break;
}
try {
return Base64.decode(string.toString().getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
throw new TorException(e);
}
}
示例4: receiveRelayResponse
import com.subgraph.orchid.TorException; //导入依赖的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;
}
}
示例5: addListeningPort
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public void addListeningPort(int port) {
if(port <= 0 || port > 65535) {
throw new TorException("Illegal listening port: "+ port);
}
synchronized(listeningPorts) {
if(isStopped) {
throw new IllegalStateException("Cannot add listening port because Socks proxy has been stopped");
}
if(listeningPorts.contains(port))
return;
listeningPorts.add(port);
try {
startListening(port);
logger.fine("Listening for SOCKS connections on port "+ port);
} catch (IOException e) {
listeningPorts.remove(port);
throw new TorException("Failed to listen on port "+ port +" : "+ e.getMessage());
}
}
}
示例6: createFromBase64
import com.subgraph.orchid.TorException; //导入依赖的package包/类
private HSDescriptorCookie createFromBase64(String b64) {
if(b64.length() != 22) {
throw new IllegalArgumentException();
}
final byte[] decoded = Base64.decode(b64 + "A=");
final byte lastByte = decoded[decoded.length - 1];
final int flag = (lastByte & 0xFF) >> 4;
final byte[] cookie = new byte[decoded.length - 1];
System.arraycopy(decoded, 0, cookie, 0, cookie.length);
switch(flag) {
case 0:
return new HSDescriptorCookie(CookieType.COOKIE_BASIC, cookie);
case 1:
return new HSDescriptorCookie(CookieType.COOKIE_STEALTH, cookie);
default:
throw new TorException("Illegal cookie descriptor with flag value: "+ flag);
}
}
示例7: createRandom
import com.subgraph.orchid.TorException; //导入依赖的package包/类
private static SecureRandom createRandom() {
try {
return SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new TorException(e);
}
}
示例8: toInetAddress
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public InetAddress toInetAddress() {
try {
return InetAddress.getByAddress(getAddressDataBytes());
} catch (UnknownHostException e) {
throw new TorException(e);
}
}
示例9: HexDigest
import com.subgraph.orchid.TorException; //导入依赖的package包/类
private HexDigest(byte[] data) {
if(data.length != TorMessageDigest.TOR_DIGEST_SIZE && data.length != TorMessageDigest.TOR_DIGEST256_SIZE) {
throw new TorException("Digest data is not the correct length "+ data.length +" != (" + TorMessageDigest.TOR_DIGEST_SIZE + " or "+ TorMessageDigest.TOR_DIGEST256_SIZE +")");
}
digestBytes = new byte[data.length];
isDigest256 = digestBytes.length == TorMessageDigest.TOR_DIGEST256_SIZE;
System.arraycopy(data, 0, digestBytes, 0, data.length);
}
示例10: decodeByte
import com.subgraph.orchid.TorException; //导入依赖的package包/类
private static int decodeByte(int bitOffset, int b0, int b1, int b2) {
switch(bitOffset % 40) {
case 0:
return ls(b0, 3) + rs(b1, 2);
case 8:
return ls(b0, 6) + ls(b1, 1) + rs (b2, 4);
case 16:
return ls(b0, 4) + rs(b1, 1);
case 24:
return ls(b0, 7) + ls(b1, 2) + rs(b2, 3);
case 32:
return ls(b0, 5) + (b1 & 0xFF);
}
throw new TorException("Illegal bit offset");
}
示例11: stringToIntVector
import com.subgraph.orchid.TorException; //导入依赖的package包/类
private static int[] stringToIntVector(String s) {
final int[] ints = new int[s.length() + 1];
for(int i = 0; i < s.length(); i++) {
int b = s.charAt(i) & 0xFF;
if(b > 0x60 && b < 0x7B)
ints[i] = b - 0x61;
else if(b > 0x31 && b < 0x38)
ints[i] = b - 0x18;
else if(b > 0x40 && b < 0x5B)
ints[i] = b - 0x41;
else
throw new TorException("Illegal character in base32 encoded string: "+ s.charAt(i));
}
return ints;
}
示例12: createSocket
import com.subgraph.orchid.TorException; //导入依赖的package包/类
SSLSocket createSocket() {
try {
final SSLSocket socket = (SSLSocket) socketFactory.createSocket();
socket.setEnabledCipherSuites(MANDATORY_CIPHERS);
socket.setUseClientMode(true);
return socket;
} catch (IOException e) {
throw new TorException(e);
}
}
示例13: getRouterListByNames
import com.subgraph.orchid.TorException; //导入依赖的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;
}
示例14: updateStatus
import com.subgraph.orchid.TorException; //导入依赖的package包/类
void updateStatus(RouterStatus status) {
if(!identityHash.equals(status.getIdentity()))
throw new TorException("Identity hash does not match status update");
this.status = status;
this.cachedCountryCode = null;
this.descriptor = null;
refreshDescriptor();
}
示例15: processDocument
import com.subgraph.orchid.TorException; //导入依赖的package包/类
public void processDocument() {
if(callbackHandler == null)
throw new TorException("DocumentFieldParser#processDocument() called with null callbackHandler");
while(true) {
final String line = readLine();
if(line == null) {
callbackHandler.endOfDocument();
return;
}
if(processLine(line))
callbackHandler.parseKeywordLine();
}
}