Please see comments below. On Saturday 28 March 2009 15:31:48 sashee at freenetproject.org wrote: > Author: sashee > Date: 2009-03-28 15:31:47 +0000 (Sat, 28 Mar 2009) > New Revision: 26255 > > Modified: > trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java > trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties > Log: > Improved the peer adder module: > -It is now possible to add multiple peers, instead of just 1. A result page will notify about the successes/failures > -The 2000 byte limit for uploading peers via file is removed > > Modified: trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java > =================================================================== > --- trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java 2009-03-28 12:42:05 UTC (rev 26254) > +++ trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java 2009-03-28 15:31:47 UTC (rev 26255) > @@ -145,6 +145,7 @@ > protected final PeerManager peers; > protected boolean isReversed = false; > protected final DecimalFormat fix1 = new DecimalFormat("##0.0%"); > + public enum PeerAdditionReturnCodes{ OK, WRONG_ENCODING, CANT_PARSE, INTERNAL_ERROR, INVALID_SIGNATURE, TRY_TO_ADD_SELF, ALREADY_IN_REFERENCE} > > @Override > public String supportedMethods() { > @@ -511,7 +512,7 @@ > String reftext = request.getPartAsString("ref", > Integer.MAX_VALUE); > reftext = reftext.trim(); > if (reftext.length() < 200) { > - reftext = request.getPartAsString("reffile", > 2000); > + reftext = request.getPartAsString("reffile", > Integer.MAX_VALUE); > reftext = reftext.trim(); > } > String privateComment = null; > @@ -551,60 +552,47 @@ > ref = new StringBuilder(ref.toString().trim()); > > request.freeParts(); > - // we have a node reference in ref > - SimpleFieldSet fs; > - > - try { > - fs = new SimpleFieldSet(ref.toString(), false, > true); > - if(!fs.getEndMarker().endsWith("End")) { > - sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), > - > L10n.getString("DarknetConnectionsToadlet.cantParseWrongEnding", new String[] { "end" }, new String[] { fs.getEndMarker() })); > - return; > + > + //Split the references string, because the peers are > added individually > + String[] nodesToAdd=ref.toString().split("End"); > + //The peer's additions results > + Map<PeerAdditionReturnCodes,Integer> results=new HashMap<PeerAdditionReturnCodes, Integer>(); > + for(int i=0;i<nodesToAdd.length;i++){ > + //We need to trim then concat 'End' to the > node's reference, this way we have a normal reference(the split() removes the 'End'-s!) > + PeerAdditionReturnCodes result=addNewNode(nodesToAdd[i].trim().concat("\nEnd"), privateComment); > + //Store the result > + if(results.containsKey(result)==false){ > + results.put(result, new Integer(0)); > } > - fs.setEndMarker("End"); // It's always End ; > the regex above doesn't always grok this > - } catch (IOException e) { > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), > - > L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { "error" }, new String[] { e.toString() })); > - return; > - } catch (Throwable t) { > - this.sendErrorPage(ctx, > l10n("failedToAddNodeInternalErrorTitle"), l10n("failedToAddNodeInternalError"), t); > - return; > + results.put(result, results.get(result)+1); > } > - PeerNode pn; > - try { > - if(isOpennet()) { > - pn = node.createNewOpennetNode(fs); > - } else { > - pn = node.createNewDarknetNode(fs); > - > ((DarknetPeerNode)pn).setPrivateDarknetCommentNote(privateComment); > + > + HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("reportOfNodeAddition"), ctx); > + HTMLNode contentNode = > ctx.getPageMaker().getContentNode(pageNode); > + > + //We create a table to show the results > + HTMLNode detailedStatusBox=new HTMLNode("table"); > + //Header of the table > + detailedStatusBox.addChild(new > HTMLNode("tr")).addChildren(new HTMLNode[]{new HTMLNode("th",l10n("resultName")),new HTMLNode("th",l10n("numOfResults"))}); > + HTMLNode statusBoxTable=detailedStatusBox.addChild(new HTMLNode("tbody")); > + //Iterate through the return codes > + for(PeerAdditionReturnCodes > returnCode:PeerAdditionReturnCodes.values()) { > + if(results.containsKey(returnCode)){ > + //Add a <tr> and 2 <td> with the name > of the code and the number of occasions it happened. If the code is OK, we use green, red elsewhere. > + statusBoxTable.addChild(new HTMLNode("tr","style","color:"+(returnCode==PeerAdditionReturnCodes.OK?"green":"red"))).addChildren(new HTMLNode[]{new HTMLNode("td",l10n("peerAdditionCode."+returnCode.toString())),new HTMLNode("td",results.get(returnCode).toString())}); > } > - } catch (FSParseException e1) { > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), > - > L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { "error" }, new String[] { e1.toString() })); > - return; > - } catch (PeerParseException e1) { > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), > - > L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { "error" }, new String[] { e1.toString() })); > - return; > - } catch (ReferenceSignatureVerificationException e1){ > - HTMLNode node = new HTMLNode("div"); > - node.addChild("#", L10n.getString("DarknetConnectionsToadlet.invalidSignature", new String[] { "error" }, new String[] { e1.toString() })); > - node.addChild("br"); > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), node); > - return; > - } catch (Throwable t) { > - this.sendErrorPage(ctx, > l10n("failedToAddNodeInternalErrorTitle"), l10n("failedToAddNodeInternalError"), t); > - return; > } > - if(Arrays.equals(pn.getIdentity(), > node.getDarknetIdentity())) { > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), l10n("triedToAddSelf")); > - return; > - } > - if(!this.node.addPeerConnection(pn)) { > - this.sendErrorPage(ctx, 200, > l10n("failedToAddNodeTitle"), l10n("alreadyInReferences")); > - return; > - } > + > + HTMLNode infobox = contentNode.addChild(ctx.getPageMaker().getInfobox("infobox",l10n("reportOfNodeAddition"))); > + HTMLNode infoboxContent = > ctx.getPageMaker().getContentNode(infobox); > + infoboxContent.addChild(detailedStatusBox); > + infoboxContent.addChild("br"); > + infoboxContent.addChild("a", "href", ".", > l10n("returnToPrevPage")); > + infoboxContent.addChild("br"); > + addHomepageLink(infoboxContent); > > + writeHTMLReply(ctx, 500, l10n("reportOfNodeAddition"), pageNode.generate()); > + > MultiValueTable<String, String> headers = new > MultiValueTable<String, String>(); > headers.put("Location", defaultRedirectLocation()); > ctx.sendReplyHeaders(302, "Found", headers, null, 0);
This looks like you are sending the reply twice, this can cause bad bugs. Please fix it. Otherwise looks great, welcome aboard, this will help your SoC applications... > Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties > =================================================================== > --- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2009-03-28 12:42:05 UTC (rev 26254) > +++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2009-03-28 15:31:47 UTC (rev 26255) > @@ -168,7 +168,7 @@ > ContentFilter.textPlainWriteAdvice=Plain text - not dangerous unless you include compromizing information > DarknetConnectionsToadlet.activityTitle=Current Activity > DarknetConnectionsToadlet.add=Add > -DarknetConnectionsToadlet.addPeerTitle=Add another peer > +DarknetConnectionsToadlet.addPeerTitle=Add another peers "Add more peers" in english. > DarknetConnectionsToadlet.alreadyInReferences=We already have the given reference. > DarknetConnectionsToadlet.backedOff=Connected but backed off: These peers are connected but we're backed off from them, so the node is not routing requests to them. > DarknetConnectionsToadlet.backedOffShort=Backed off > @@ -254,6 +254,17 @@ > DarknetConnectionsToadlet.updateChangedPrivnotes=Update changed private notes > DarknetConnectionsToadlet.urlReference=OR enter the URL of the node reference here: > DarknetConnectionsToadlet.versionTitle=Version > +DarknetConnectionsToadlet.reportOfNodeAddition=Report of node additions > +DarknetConnectionsToadlet.returnToPrevPage=Return to previous page > +DarknetConnectionsToadlet.peerAdditionCode.OK=Added successfully > +DarknetConnectionsToadlet.peerAdditionCode.TRY_TO_ADD_SELF=Tried to add self > +DarknetConnectionsToadlet.peerAdditionCode.WRONG_ENCODING=Wrong encoding > +DarknetConnectionsToadlet.peerAdditionCode.CANT_PARSE=Can't parse > +DarknetConnectionsToadlet.peerAdditionCode.INTERNAL_ERROR=Internal error > +DarknetConnectionsToadlet.peerAdditionCode.INVALID_SIGNATURE=Invalid signature > +DarknetConnectionsToadlet.peerAdditionCode.ALREADY_IN_REFERENCE=Already in reference > +DarknetConnectionsToadlet.resultName=Name of result Just "Result" would probably be better. > +DarknetConnectionsToadlet.numOfResults=Number of results > ExtOldAgeUserAlert.extTooOld=Your freenet-ext.jar file seems to be outdated: we strongly advise you to update it using http://downloads.freenetproject.org/alpha/freenet-ext.jar. > ExtOldAgeUserAlert.extTooOldTitle=Freenet-ext too old > ExtOldAgeUserAlert.extTooOldShort=Your freenet-ext.jar is out of date. Please upgrade. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 835 bytes Desc: This is a digitally signed message part. URL: <https://emu.freenetproject.org/pipermail/devl/attachments/20090401/f61451a5/attachment.pgp>