/** * Not synchronized, the involved identity might be deleted during the query - which is not really * a problem. */ public List<WoTTrust> getReceivedTrusts(Identity trustee) throws Exception { List<WoTTrust> result = new ArrayList<WoTTrust>(); SimpleFieldSet request = new SimpleFieldSet(true); request.putOverwrite("Message", "GetTrusters"); request.putOverwrite("Context", ""); request.putOverwrite("Identity", trustee.getID()); try { SimpleFieldSet answer = sendFCPMessageBlocking(request, null, "Identities").params; for (int idx = 0; ; idx++) { String id = answer.get("Identity" + idx); if (id == null || id.equals("")) /* TODO: Figure out whether the second condition is necessary */ break; try { final WoTTrust trust = new WoTTrust( getIdentity(id), trustee, (byte) Integer.parseInt(answer.get("Value" + idx)), answer.get("Comment" + idx)); mWoTCache.putTrust(trust); result.add(trust); } catch (NoSuchIdentityException e) { } catch (InvalidParameterException e) { } } } catch (PluginNotFoundException e) { throw new WoTDisconnectedException(); } return result; }
/** * Not synchronized, the involved identities might be deleted during the query - which is not * really a problem. */ public byte getTrust(final WoTOwnIdentity truster, final WoTIdentity trustee) throws NotTrustedException, Exception { if (mIsUnitTest) return 0; final String trust = getProperty(truster, trustee, "Trust"); if (trust.equals("null")) throw new NotTrustedException(truster, trustee); final byte value = Byte.parseByte(trust); mWoTCache.putTrust(truster, trustee, value); return value; }
/** * Not synchronized, the involved identities might be deleted during the query - which is not * really a problem. */ public int getScore(final WoTOwnIdentity truster, final WoTIdentity trustee) throws NotInTrustTreeException, Exception { if (mIsUnitTest) return 0; final String score = getProperty(truster, trustee, "Score"); if (score.equals("null")) throw new NotInTrustTreeException(truster, trustee); final int value = Integer.parseInt(score); mWoTCache.putScore(truster, trustee, value); return value; }
/** * Not synchronized, the involved identities might be deleted during the query or some other WoT * client might modify the trust value during the query - which is not really a problem, you * should not be modifying trust values of your own identity with multiple clients simultaneously. */ public void setTrust(OwnIdentity truster, Identity trustee, byte trust, String comment) throws Exception { WoTOwnIdentity wotTruster = (WoTOwnIdentity) truster; WoTIdentity wotTrustee = (WoTIdentity) trustee; SimpleFieldSet request = new SimpleFieldSet(true); request.putOverwrite("Message", "SetTrust"); request.putOverwrite("Truster", wotTruster.getID()); request.putOverwrite("Trustee", wotTrustee.getID()); request.putOverwrite("Value", Integer.toString(trust)); request.putOverwrite("Comment", comment); sendFCPMessageBlocking(request, null, "TrustSet"); mWoTCache.putTrust(wotTruster, wotTrustee, trust); }