private void addIdentities(SimpleFieldSet sfs) { // System.out.println("Adding all identities"); // clear current identities (requests refresh identities.clear(); // iterate over identities and store them (for resolving nick later on) int i = 0; try { while (!sfs.getString("Identity" + i).equals("")) { HashMap<String, String> identity = new HashMap<String, String>(); identity.put("ID", sfs.getString("RequestURI" + i).split("/")[0].replace("USK@", "")); identity.put("nick", sfs.getString("Nickname" + i)); identity.put("Value", sfs.getString("Value" + i)); identity.put("Identity", sfs.getString("Identity" + i)); // System.out.println("Added identity: " + identity.get("nick")); // check that the identity isn't already in the map boolean add = true; for (Map<String, String> existingIdentity : identities) { if (existingIdentity.get("ID").equals(identity.get("ID"))) add = false; } if (add) identities.add(identity); i++; } } catch (FSParseException e) { // triggered when we've reached the end of the identity list locked_all = false; } // FIXME: hack for broken WoT (from the perspective of freenet2/freenet1 on testnet) if (Frirc.DEBUG) { HashMap<String, String> identity = new HashMap<String, String>(); identity.put( "ID", "67gJMSsyOg0OqifgD-Aebtw8XwKVx~vjVuRbo0WXsI4,4tbrCVGd3fvNTAwUxVZFFzaqoskEp85HgBkwpe~hiD0,AQACAAE"); identity.put("nick", "freenet1"); identity.put("Value", "100"); identities.add(identity); HashMap<String, String> identity2 = new HashMap<String, String>(); identity2.put( "ID", "enQbW4kdLsYqFCLtq~a4OquE5uwKa3nHFqLih64j5KU,ROkkyPxiFajC2N7RUs4oRVw2iotEp-hOV4EID0BRC9g,AQACAAE"); identity2.put("nick", "freenet2"); identity2.put("Value", "100"); identities.add(identity2); } }
/** * Method called upon receiving an FCP message, determines message type and calls correct method */ @Override public void onReply(String plugin, String channel, SimpleFieldSet sfs, Bucket arg3) { try { // System.out.println("Message received = " + sfs.get("Message")); if (sfs.getString("Message").equals("OwnIdentities")) { addOwnIdentities(sfs); } else if (sfs.getString("Message").equals("Identities")) { addIdentities(sfs); } else { // System.out.println("Message received = " + sfs.get("OriginalMessage")); // System.out.println("Message received = " + sfs.get("Description")); } } catch (FSParseException e) { // no message field, shouldn't happen e.printStackTrace(); } }
/** * Process the WoT fcp message containing our identities and add them to the local store * * @param sfs */ private void addOwnIdentities(SimpleFieldSet sfs) { int i = 0; try { while (!sfs.getString("Identity" + i).equals("")) { HashMap<String, String> identity = new HashMap<String, String>(); identity.put("ID", sfs.getString("RequestURI" + i).split("/")[0].replace("USK@", "")); identity.put("insertID", sfs.getString("InsertURI" + i).split("/")[0].replace("USK@", "")); identity.put("nick", sfs.getString("Nickname" + i)); identity.put("Identity", sfs.getString("Identity" + i)); ownIdentities.add(identity); if (Frirc.DEBUG) System.out.println( "Identity added from WoT: " + identity.get("nick") + " (" + identity.get("ID") + ")"); ++i; } } catch (FSParseException e) { // triggered when we've reached the end of the identity list locked_own = new Boolean(false); } }