diff --git a/src/main/java/net/sharkfw/asip/engine/ASIPInMessage.java b/src/main/java/net/sharkfw/asip/engine/ASIPInMessage.java index 448a696b..e24611c2 100644 --- a/src/main/java/net/sharkfw/asip/engine/ASIPInMessage.java +++ b/src/main/java/net/sharkfw/asip/engine/ASIPInMessage.java @@ -77,7 +77,7 @@ public void parse() throws IOException, SharkSecurityException { response.append(buffer, 0, charsRead) ; } while(charsRead == buffer.length); - L.d("Read " + response.toString().length() + " Bytes of Data.", this); +// L.d("Read " + response.toString().length() + " Bytes of Data.", this); // L.d(response.toString(), this); if(!response.toString().isEmpty()){ diff --git a/src/main/java/net/sharkfw/asip/serialization/ASIPSerializationHolder.java b/src/main/java/net/sharkfw/asip/serialization/ASIPSerializationHolder.java index 3403adf4..47ffcb46 100644 --- a/src/main/java/net/sharkfw/asip/serialization/ASIPSerializationHolder.java +++ b/src/main/java/net/sharkfw/asip/serialization/ASIPSerializationHolder.java @@ -34,7 +34,7 @@ public class ASIPSerializationHolder { public ASIPSerializationHolder(String message) throws ASIPSerializerException { if(!message.isEmpty()){ protocolConfig = message.substring(0, jsonMessageBeginIndex); - L.d("ProtocolConfig: " + protocolConfig, this); +// L.d("ProtocolConfig: " + protocolConfig, this); String format = protocolConfig.substring(0, fieldLengthFormat); String version = protocolConfig.substring(fieldLengthFormat, fieldLengthFormat + fieldLengthVersion); String messageLengthTemp = protocolConfig.substring(fieldLengthFormat + fieldLengthVersion, jsonMessageBeginIndex); @@ -42,9 +42,9 @@ public ASIPSerializationHolder(String message) throws ASIPSerializerException { try { messageLength = Integer.parseInt(messageLengthTemp); - L.d("MessageLength=" + messageLength, this); - L.d("message.length=" + message.length(), this); - L.d("jsonMessageBeginIndex + messageLength=" + (jsonMessageBeginIndex + messageLength), this); +// L.d("MessageLength=" + messageLength, this); +// L.d("message.length=" + message.length(), this); +// L.d("jsonMessageBeginIndex + messageLength=" + (jsonMessageBeginIndex + messageLength), this); } catch (NumberFormatException e){ throw new ASIPSerializerException("String can't be converted to an Integer: " + e.getMessage()); } diff --git a/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncInviteKP.java b/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncInviteKP.java index a6c7ef0e..afd93bbc 100644 --- a/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncInviteKP.java +++ b/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncInviteKP.java @@ -76,8 +76,9 @@ protected void handleExpose(ASIPInMessage message, ASIPConnection asipConnection InMemoSharkKB.createInMemoTimeSTSet() ); + interest.getApprovers().merge(this.se.getOwner()); + SyncComponent component = syncManager.createSyncComponent(inMemoSharkKB, next, interest.getApprovers(), interest.getSender(), true); - component.addApprovedMember(this.se.getOwner()); // Trigger the listeners syncManager.triggerInviteListener(component); } @@ -89,8 +90,6 @@ protected void handleExpose(ASIPInMessage message, ASIPConnection asipConnection typeSet.merge(SyncManager.SHARK_SYNC_OFFER_TAG); interest.setTypes(typeSet); - interest.getApprovers().merge(this.se.getOwner()); - // Set myself as sender interest.setSender(this.se.getOwner()); diff --git a/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncManager.java b/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncManager.java index 0cf1503f..c7989f25 100644 --- a/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncManager.java +++ b/src/main/java/net/sharkfw/knowledgeBase/sync/manager/SyncManager.java @@ -222,10 +222,7 @@ private boolean checkInvitation(SyncComponent component){ // Should not be possible because the creator of the component will be added as well. return false; } else{ - PeerSTSet inMemoCopy = InMemoSharkKB.createInMemoCopy(approvedMembers); - inMemoCopy.removeSemanticTag(this.engine.getOwner()); - // Remove ourself from the list - if(inMemoCopy.isEmpty()){ + if(approvedMembers.isEmpty()){ // for now we have no one who participates in our syncGroup // We have to send invites to everyone! this.sendInvite(component); @@ -236,7 +233,12 @@ private boolean checkInvitation(SyncComponent component){ if (!SharkCSAlgebra.identical(members, approvedMembers)) { // There are still some people missing so we are sending out our invites! // TODO SendInvite? -// this.sendInvite(component); + Enumeration enumeration = members.peerTags(); + while (enumeration.hasMoreElements()){ + PeerSemanticTag peerSemanticTag = enumeration.nextElement(); + } + this.sendInvite(component); + return false; } return true; } @@ -258,8 +260,6 @@ public void sendMerge(SyncComponent component){ if(checkInvitation(component) == false) return; - L.d("Invitation successful.", this); - PeerSTSet approvedMembers = component.getApprovedMembers(); // Okay so now we are finished with our invites! // Let's send our merge! @@ -269,7 +269,7 @@ public void sendMerge(SyncComponent component){ PeerSemanticTag peerSemanticTag = approvedMemberEnumeration.nextElement(); // Okay now that we have a peer we can send our changes to // we have to check if we have already merged with the peer and get the date of the last merge. - + L.d("Name of approvedMember: " + peerSemanticTag.getName(), this); // Now check if we are the peer if(!SharkCSAlgebra.identical(peerSemanticTag, this.engine.getOwner())){ sendMerge(component, peerSemanticTag); @@ -287,20 +287,23 @@ public void sendMerge(SyncComponent component, PeerSemanticTag peer){ L.d("Initiated sending a merge to a special peer.", this); try { - if (!component.isInvited(peer)) return; - SharkKB changes = getChanges(component, peer); - if(changes!=null){ - // We do have some changes we can send! - ASIPOutMessage outMessage = this.engine.createASIPOutMessage( - peer.getAddresses(), - this.engine.getOwner(), - peer, - null, - null, - component.getUniqueName(), - SyncManager.SHARK_SYNC_MERGE_TAG, 1); - - outMessage.insert(changes); + if (component.isInvited(peer)){ + SharkKB changes = getChanges(component, peer); + if(changes!=null){ + // We do have some changes we can send! + ASIPOutMessage outMessage = this.engine.createASIPOutMessage( + peer.getAddresses(), + this.engine.getOwner(), + peer, + null, + null, + component.getUniqueName(), + SyncManager.SHARK_SYNC_MERGE_TAG, 1); + + outMessage.insert(changes); + } + } else { + sendInvite(component, peer); } } catch (SharkKBException e) { L.e(e.getMessage(), this); @@ -337,6 +340,8 @@ public void sendInvite(SyncComponent component) throws SharkKBException { while (enumeration.hasMoreElements()){ PeerSemanticTag peerSemanticTag = enumeration.nextElement(); + if (SharkCSAlgebra.identical(peerSemanticTag, this.engine.getOwner())) continue; + if(!component.isInvited(peerSemanticTag)){ String[] peerSemanticTagAddresses = peerSemanticTag.getAddresses(); if(peerSemanticTagAddresses==null || peerSemanticTagAddresses.length<=0) continue;