Author: zothar
Date: 2007-04-22 21:39:07 +0000 (Sun, 22 Apr 2007)
New Revision: 12875

Modified:
   trunk/freenet/src/freenet/node/fcp/AddPeer.java
   trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
Log:
Better ProtocolError codes when using FCP's AddPeer: REF_SIGNATURE_INVALID, 
CANNOT_PEER_WITH_SELF and DUPLICATE_PEER_REF

Modified: trunk/freenet/src/freenet/node/fcp/AddPeer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/AddPeer.java     2007-04-22 20:29:55 UTC 
(rev 12874)
+++ trunk/freenet/src/freenet/node/fcp/AddPeer.java     2007-04-22 21:39:07 UTC 
(rev 12875)
@@ -112,16 +112,19 @@
                try {
                        pn = new PeerNode(fs, node, node.peers, false);
                } catch (FSParseException e) {
-                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
retrieved ref: "+e.getMessage(), null, false);
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
                } catch (PeerParseException e) {
-                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
retrieved ref: "+e.getMessage(), null, false);
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref: "+e.getMessage(), null, false);
                } catch (ReferenceSignatureVerificationException e) {
-                       // TODO: maybe a special ProtocolErrorMessage ?
-                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
retrieved ref: "+e.getMessage(), null, false);
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_SIGNATURE_INVALID, "Error 
adding ref: "+e.getMessage(), null, false);
                }
-               // **FIXME** Handle duplicates somehow maybe?  What about when 
node.addDarknetConnection() fails for some reason?
-               if(node.addDarknetConnection(pn))
-                       System.out.println("Added peer: "+pn);
+               if(pn.getIdentityHash()==node.getIdentityHash()) {
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.CANNOT_PEER_WITH_SELF, "Node 
cannot peer with itself", null, false);
+               }
+               if(!node.addDarknetConnection(pn)) {
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.DUPLICATE_PEER_REF, "Node already 
has a peer with that identity", null, false);
+               }
+               System.out.println("Added peer: "+pn);
                handler.outputHandler.queue(new Peer(pn, true, true));
        }


Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2007-04-22 20:29:55 UTC (rev 12874)
+++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2007-04-22 21:39:07 UTC (rev 12875)
@@ -48,6 +48,9 @@
        static final int ACCESS_DENIED = 24;
        static final int DIRECT_DISK_ACCESS_DENIED = 25;
        static final int COULD_NOT_READ_FILE = 26;
+       static final int REF_SIGNATURE_INVALID = 27;
+       static final int CANNOT_PEER_WITH_SELF = 28;
+       static final int DUPLICATE_PEER_REF = 29;

        final int code;
        final String extra;


Reply via email to