Skip to content

Commit b02c863

Browse files
committed
about fixing online message exchange but - snapshot - still works
1 parent 0d69691 commit b02c863

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

src/main/java/net/sharksystem/asap/engine/ASAPChunkStorageFS.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ String getChunkFileTrunkname(int era, String uri) {
7474
String setupChunkFolder(int era, String targetUrl) {
7575
String eraFolderString = this.getPath(era);
7676
File eraFolder = new File(eraFolderString);
77+
Log.writeLog(this, "setup chunk / era folder: " + eraFolderString);
7778
if(!eraFolder.exists()) {
79+
Log.writeLog(this, "folder does not exist - create: " + eraFolderString);
7880
eraFolder.mkdirs();
7981
}
8082

src/main/java/net/sharksystem/asap/engine/ASAPEngine.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,13 @@ private ASAPInternalChunk getIncomingChunk(String encounteredPeer, ASAP_Assimila
497497
Log.writeLog(this, this.toString(), "got incoming chunk storage "
498498
+ incomingChunkStorage);
499499

500-
// get local target for data to come
500+
// get local target for data to come
501501
if (!incomingChunkStorage.existsChunk(uri, eraSender)) {
502502
ASAPInternalChunk localChunk = null;
503503
// is there a local chunk - to clone recipients from?
504504
if (this.channelExists(uri)) {
505-
localChunk = this.getStorage().getChunk(uri, this.getEra());
505+
// localChunk = incomingChunkStorage.getChunk(uri, this.getEra());
506+
localChunk = incomingChunkStorage.getChunk(uri, eraSender);
506507
} else {
507508
Log.writeLog(this, this.toString(), "asked to set up new channel: (uri/senderE2E): "
508509
+ uri + " | " + senderE2E);

src/main/java/net/sharksystem/asap/engine/ASAPInternalChunkFS.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.sharksystem.asap.ASAPHop;
66
import net.sharksystem.asap.utils.ASAPSerialization;
77
import net.sharksystem.asap.utils.Helper;
8+
import net.sharksystem.utils.Log;
89

910
import java.io.*;
1011
import java.util.*;
@@ -115,7 +116,7 @@ private void initFiles(String trunkName) throws IOException {
115116

116117
// try to read existing meta data
117118
if(!this.readMetaData(this.metaFile)) {
118-
// no metadate to be read - set defaults
119+
// no meta date to be read - set defaults
119120
this.writeMetaData(this.metaFile);
120121
this.recipients = new HashSet<>();
121122
this.deliveredTo = new ArrayList<>();
@@ -180,21 +181,32 @@ public void addMessage(byte[] messageAsBytes) throws IOException {
180181
}
181182

182183
public void addMessage(InputStream messageByteIS, long length) throws IOException {
184+
Log.writeLog(this, "going to add message to chunkFS" );
183185
if(length > Integer.MAX_VALUE) {
184186
throw new IOException("message must not be longer than Integer.MAXVALUE");
185187
}
186188

187-
long offset = this.messageFile.length();
189+
long offset = 0;
190+
if(!this.messageFile.exists()) {
191+
Log.writeLog(this, "content file does not exist yet - create: " + this.messageFile.getName());
192+
Log.writeLog(this, "apath " + this.messageFile.getAbsolutePath());
193+
Log.writeLog(this, "cpath " + this.messageFile.getCanonicalPath());
194+
Log.writeLog(this, "path " + this.messageFile.getPath());
195+
this.messageFile.createNewFile();
196+
} else {
197+
offset = this.messageFile.length();
198+
}
199+
Log.writeLog(this, "got chunk content file length: " + offset);
188200

189-
// Log.writeLog(this, "chunk file offset == " + offset);
190201
OutputStream os = new FileOutputStream(this.messageFile, true);
202+
Log.writeLog(this, "opened chunk content file to append data");
191203

192-
// Log.writeLog(this, "write message to the end of chunk file");
204+
Log.writeLog(this, "write message to the end of chunk file");
193205
while(length-- > 0) {
194206
os.write(messageByteIS.read());
195207
}
196208

197-
// Log.writeLog(this, "closing");
209+
Log.writeLog(this, "closing");
198210
os.close();
199211

200212
// remember offset if not 0

src/main/java/net/sharksystem/asap/utils/PeerIDHelper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import net.sharksystem.asap.ASAP;
44

55
public class PeerIDHelper {
6-
private static long lastCall = 0;
7-
86
public static boolean sameID(CharSequence idA, CharSequence idB) {
97
if(idA.length() != idB.length()) return false;
108

@@ -26,14 +24,6 @@ public static boolean sameUri(CharSequence uriA, CharSequence uriB) {
2624
}
2725

2826
public static String createUniqueID() {
29-
if(lastCall == System.currentTimeMillis()) {
30-
try {
31-
Thread.sleep(1);
32-
} catch (InterruptedException e) {
33-
e.printStackTrace();
34-
}
35-
}
36-
lastCall = System.currentTimeMillis();
3727
return ASAP.createUniqueID();
3828
}
3929
}

src/test/java/net/sharksystem/asap/peer/Point2Point2Test2.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import net.sharksystem.TestHelper;
55
import net.sharksystem.asap.ASAP;
66
import net.sharksystem.asap.ASAPException;
7-
import net.sharksystem.asap.engine.ASAPInternalChunk;
8-
import net.sharksystem.asap.utils.PeerIDHelper;
97
import net.sharksystem.testsupport.ASAPTestPeerFS;
108
import net.sharksystem.testsupport.StoreReceivedMessages;
119
import net.sharksystem.utils.Utils;
@@ -35,8 +33,8 @@ public void point2point1() throws IOException, ASAPException, InterruptedExcepti
3533
String uri = "asapExample://uriExample";
3634
byte[] message = "ASAP example message".getBytes(StandardCharsets.UTF_8);
3735

38-
String aliceID = PeerIDHelper.createUniqueID();
39-
String bobID = PeerIDHelper.createUniqueID();
36+
String aliceID = TestConstants.ALICE_ID;
37+
String bobID = TestConstants.BOB_ID;
4038
String aliceDirectory = WORKING_SUB_DIRECTORY + "/" + aliceID;
4139
String bobDirectory = WORKING_SUB_DIRECTORY + "/" + bobID;
4240

@@ -59,13 +57,13 @@ public void point2point1() throws IOException, ASAPException, InterruptedExcepti
5957
System.out.println("\n>>>>>>>>>>>>>>>>>>> send message #1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
6058
aliceSimplePeer.sendASAPMessage(appName, uri, message);
6159
Thread.sleep(100);
60+
//Thread.sleep(Long.MAX_VALUE);
6261

6362
Assert.assertEquals(1, bobListener.messageList.size());
6463

6564
byte[] messageReceived = bobListener.messageList.get(0).getMessages().next();
6665
Assert.assertTrue(Utils.compareArrays(messageReceived, message));
6766

6867
aliceSimplePeer.stopEncounter(bobSimplePeer);
69-
//Thread.sleep(Long.MAX_VALUE);
7068
}
7169
}

0 commit comments

Comments
 (0)