Author: toad
Date: 2008-04-05 15:11:32 +0000 (Sat, 05 Apr 2008)
New Revision: 19034

Modified:
   trunk/freenet/src/freenet/node/fcp/AddPeer.java
Log:
AddPeer: support Identifier properly, send it back on ALL error messages if set.

Modified: trunk/freenet/src/freenet/node/fcp/AddPeer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/AddPeer.java     2008-04-05 14:59:33 UTC 
(rev 19033)
+++ trunk/freenet/src/freenet/node/fcp/AddPeer.java     2008-04-05 15:11:32 UTC 
(rev 19034)
@@ -28,9 +28,12 @@
        public static final String NAME = "AddPeer";

        SimpleFieldSet fs;
+       final String identifier;

        public AddPeer(SimpleFieldSet fs) {
                this.fs = fs;
+               this.identifier = fs.get("Identifier");
+               fs.removeValue("Identifier");
        }

        public SimpleFieldSet getFieldSet() {
@@ -43,7 +46,7 @@

        public void run(FCPConnectionHandler handler, Node node) throws 
MessageInvalidException {
                if(!handler.hasFullAccess()) {
-                       throw new 
MessageInvalidException(ProtocolErrorMessage.ACCESS_DENIED, "AddPeer requires 
full access", fs.get("Identifier"), false);
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.ACCESS_DENIED, "AddPeer requires 
full access", identifier, false);
                }
                String urlString = fs.get("URL");
                String fileString = fs.get("File");
@@ -63,26 +66,26 @@
                                }
                                in.close();
                        } catch (MalformedURLException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "Error parsing 
ref URL <"+urlString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "Error parsing 
ref URL <"+urlString+">: "+e.getMessage(), identifier, false);
                        } catch (IOException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "IO error while 
retrieving ref URL <"+urlString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "IO error while 
retrieving ref URL <"+urlString+">: "+e.getMessage(), identifier, false);
                        }
                        ref = new StringBuffer(ref.toString().trim());
                        if(ref == null) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+ '>', null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+ '>', identifier, false);
                        }
                        if("".equals(ref.toString())) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+ '>', null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+ '>', identifier, false);
                        }
                        try {
                                fs = new SimpleFieldSet(ref.toString(), false, 
true);
                        } catch (IOException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">: "+e.getMessage(), identifier, false);
                        }
                } else if(fileString != null) {
                        File f = new File(fileString);
                        if(!f.isFile()) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.NOT_A_FILE_ERROR, "The given ref 
file path <"+fileString+"> is not a file", null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.NOT_A_FILE_ERROR, "The given ref 
file path <"+fileString+"> is not a file", identifier, false);
                        }
                        try {
                                in = new BufferedReader(new FileReader(f));
@@ -94,21 +97,21 @@
                                }
                                in.close();
                        } catch (FileNotFoundException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, "File not found 
when retrieving ref file <"+fileString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, "File not found 
when retrieving ref file <"+fileString+">: "+e.getMessage(), identifier, false);
                        } catch (IOException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_PARSE_ERROR, "IO error while 
retrieving ref file <"+fileString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_PARSE_ERROR, "IO error while 
retrieving ref file <"+fileString+">: "+e.getMessage(), identifier, false);
                        }
                        ref = new StringBuffer(ref.toString().trim());
                        if(ref == null) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+ '>', null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+ '>', identifier, false);
                        }
                        if("".equals(ref.toString())) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+ '>', null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+ '>', identifier, false);
                        }
                        try {
                                fs = new SimpleFieldSet(ref.toString(), false, 
true);
                        } catch (IOException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">: "+e.getMessage(), identifier, false);
                        }
                }
                fs.setEndMarker( "End" );
@@ -118,34 +121,34 @@
                        try {
                                pn = node.createNewOpennetNode(fs);
                        } catch (FSParseException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), identifier, false);
                        } catch (OpennetDisabledException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.OPENNET_DISABLED, "Error adding 
ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.OPENNET_DISABLED, "Error adding 
ref: "+e.getMessage(), identifier, false);
                        } catch (PeerParseException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), identifier, false);
                        } catch (ReferenceSignatureVerificationException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_SIGNATURE_INVALID, "Error 
adding ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_SIGNATURE_INVALID, "Error 
adding ref: "+e.getMessage(), identifier, false);
                        }
                        if(Arrays.equals(pn.getIdentity(), 
node.getOpennetIdentity()))
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.CANNOT_PEER_WITH_SELF, "Node 
cannot peer with itself", null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.CANNOT_PEER_WITH_SELF, "Node 
cannot peer with itself", identifier, false);
                        if(!node.addPeerConnection(pn)) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.DUPLICATE_PEER_REF, "Node already 
has a peer with that identity", null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.DUPLICATE_PEER_REF, "Node already 
has a peer with that identity", identifier, false);
                        }
                        System.out.println("Added opennet peer: "+pn);
                } else {
                        try {
                                pn = node.createNewDarknetNode(fs);
                        } catch (FSParseException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), identifier, false);
                        } catch (PeerParseException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), identifier, false);
                        } catch (ReferenceSignatureVerificationException e) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_SIGNATURE_INVALID, "Error 
adding ref: "+e.getMessage(), null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_SIGNATURE_INVALID, "Error 
adding ref: "+e.getMessage(), identifier, false);
                        }
                        if(Arrays.equals(pn.getIdentity(), 
node.getDarknetIdentity()))
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.CANNOT_PEER_WITH_SELF, "Node 
cannot peer with itself", null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.CANNOT_PEER_WITH_SELF, "Node 
cannot peer with itself", identifier, false);
                        if(!node.addPeerConnection(pn)) {
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.DUPLICATE_PEER_REF, "Node already 
has a peer with that identity", null, false);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.DUPLICATE_PEER_REF, "Node already 
has a peer with that identity", identifier, false);
                        }
                        System.out.println("Added darknet peer: "+pn);
                }


Reply via email to