Skip to content

Commit

Permalink
Remove logs and fixing issues sending a merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4rvis committed Jan 11, 2017
1 parent fe3655c commit 6f281ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sharkfw/asip/engine/ASIPInMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ 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);
messageLengthTemp = messageLengthTemp.replaceFirst("^0+(?!$)", "");

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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<PeerSemanticTag> enumeration = members.peerTags();
while (enumeration.hasMoreElements()){
PeerSemanticTag peerSemanticTag = enumeration.nextElement();
}
this.sendInvite(component);
return false;
}
return true;
}
Expand All @@ -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!
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6f281ad

Please sign in to comment.