Skip to content

Commit

Permalink
Proper outsider cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Aug 28, 2020
1 parent 6515d2f commit 8449151
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 41 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Expand Up @@ -69,7 +69,7 @@ pinned_maven_install()
git_repository(
name = "snowblossom",
remote = "https://github.com/snowblossomcoin/snowblossom",
commit = "7bfed44ac172fdb69d477c3d4772eefd32e33e72",
commit = "595296b74598461034f0051d18f1e7c73a78b783",
shallow_since = "1595994852 -0700"
)

Expand Down
27 changes: 25 additions & 2 deletions src/ChannelAccess.java
Expand Up @@ -13,7 +13,8 @@
import snowblossom.channels.proto.SignedMessagePayload;
import snowblossom.client.StubHolder;
import snowblossom.lib.ValidationException;
import snowblossom.util.proto.SymmetricKey;
import snowblossom.lib.ChainHash;
import java.io.ByteArrayOutputStream;

/**
* Main view and access to a channel for modules that shouldn't have full low level access
Expand Down Expand Up @@ -62,7 +63,7 @@ public List<SignedMessage> getOutsiderByTime(int max_return, boolean oldest_firs
TreeMap<Double, SignedMessage> message_map = new TreeMap<>();
Random rnd = new Random();

for(SignedMessage sm : ctx.db.getOutsiderMap().getByPrefix(ByteString.EMPTY, 50000).values())
for(SignedMessage sm : ctx.db.getOutsiderMap().getByPrefix(ByteString.EMPTY, 50000, true).values())
{
try
{
Expand Down Expand Up @@ -145,4 +146,26 @@ public ChannelAccess openOtherChannel(ChannelID cid)

}

/**
* Reads file from channel or null if it isn't there
*/
public ByteString readFile(String path)
throws java.io.IOException, ValidationException
{
ByteString content_id = ChanDataUtils.getData(ctx, path);
if (content_id == null) return null;
SignedMessage content_msg = ctx.db.getContentMap().get(content_id);
if (content_msg == null) return null;

ContentInfo ci = ChannelSigUtil.quickPayload(content_msg).getContentInfo();

ByteArrayOutputStream out = new ByteArrayOutputStream();
BlockReadUtils.streamContentOut(ctx, new ChainHash(content_id), ci, out, node.getUserWalletDB());

return ByteString.copyFrom(out.toByteArray());



}

}
3 changes: 2 additions & 1 deletion src/ChannelGlobals.java
Expand Up @@ -3,7 +3,7 @@

public class ChannelGlobals
{
public static final String VERSION = "v0.6.0-2020.08.26.00";
public static final String VERSION = "v0.6.0-2020.08.27.02";

public static final String USER_ADDRESS_STRING="user";
public static final String NODE_ADDRESS_STRING="node";
Expand Down Expand Up @@ -64,3 +64,4 @@ public class ChannelGlobals

}


35 changes: 19 additions & 16 deletions src/ChannelOutsiderSender.java
Expand Up @@ -82,31 +82,34 @@ private void startSend(ChannelID cid)
{
//TODO - use random rather than just getting everything
ArrayList<SignedMessage> full_list = new ArrayList<>();

full_list.addAll(ctx.db.getOutsiderMap().getByPrefix(ByteString.EMPTY, 100000).values());
full_list.addAll(ctx.db.getOutsiderMap().getByPrefix(ByteString.EMPTY, 100000, true).values());
if (full_list.size() == 0) return;

Random rnd = new Random();

SignedMessage sm = full_list.get(rnd.nextInt(full_list.size()));
//Random rnd = new Random();
//SignedMessage sm = full_list.get(rnd.nextInt(full_list.size()));

try
for(SignedMessage sm : full_list)
{
ChannelValidation.validateOutsiderContent(sm, ctx.block_ingestor.getHead(), ctx);
try
{
ChannelValidation.validateOutsiderContent(sm, ctx.block_ingestor.getHead(), ctx);

ChannelPeerMessage m_out = ChannelPeerMessage.newBuilder()
.setChannelId(cid.getBytes())
.setContent(sm)
.build();
ChannelPeerMessage m_out = ChannelPeerMessage.newBuilder()
.setChannelId(cid.getBytes())
.setContent(sm)
.build();

for(ChannelLink link : ctx.getLinks())
for(ChannelLink link : ctx.getLinks())
{
link.writeMessage(m_out);
}
}
catch(ValidationException e)
{
link.writeMessage(m_out);
ctx.db.getOutsiderMap().remove( sm.getMessageId() );
}
}
catch(ValidationException e)
{
ctx.db.getOutsiderMap().remove( sm.getMessageId() );

}


Expand Down
19 changes: 9 additions & 10 deletions src/FileBlockImportSettings.java
@@ -1,19 +1,16 @@
package snowblossom.channels;

import java.io.File;
import snowblossom.node.StatusInterface;
import snowblossom.proto.WalletDatabase;
import snowblossom.util.proto.SymmetricKey;
import snowblossom.lib.ValidationException;
import snowblossom.channels.proto.EncryptedChannelConfig;


import com.google.protobuf.util.JsonFormat;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;

import snowblossom.channels.proto.EncryptedChannelConfig;
import snowblossom.lib.Globals;
import snowblossom.lib.ValidationException;
import snowblossom.node.StatusInterface;
import snowblossom.proto.WalletDatabase;
import snowblossom.util.proto.SymmetricKey;

public class FileBlockImportSettings
{
Expand Down Expand Up @@ -62,6 +59,8 @@ public boolean encrypt(String prefix)
public void setupEncrypt(ChannelContext ctx, ChannelNode node)
throws ValidationException
{
Globals.addCryptoProvider();

File settings_file = new File(base_path, "encryption.json");

if (settings_file.exists())
Expand Down
4 changes: 1 addition & 3 deletions src/JsonTest.java
@@ -1,11 +1,9 @@
package snowblossom.channels;

import com.google.protobuf.util.JsonFormat;

import snowblossom.channels.proto.EncryptedChannelConfig;
import snowblossom.channels.proto.OfferCurrency;
import snowblossom.channels.proto.Offer;

import snowblossom.channels.proto.OfferCurrency;

public class JsonTest
{
Expand Down
2 changes: 0 additions & 2 deletions src/Mimer.java
Expand Up @@ -568,5 +568,3 @@ public static String guessContentType(String path)
}

}


6 changes: 5 additions & 1 deletion src/iceleaf/ChannelNodePanel.java
@@ -1,5 +1,6 @@
package snowblossom.channels.iceleaf;

import com.google.protobuf.ByteString;
import duckutil.ConfigMem;
import duckutil.PeriodicThread;
import java.awt.GridBagConstraints;
Expand All @@ -20,11 +21,11 @@
import snowblossom.channels.ChannelLink;
import snowblossom.channels.ChannelNode;
import snowblossom.channels.ChunkMapUtils;
import snowblossom.channels.FileBlockImportSettings;
import snowblossom.channels.MiscUtils;
import snowblossom.channels.PeerLink;
import snowblossom.channels.PrintUtil;
import snowblossom.channels.SocksServer;
import snowblossom.channels.FileBlockImportSettings;
import snowblossom.channels.proto.ChannelPeerInfo;
import snowblossom.iceleaf.BasePanel;
import snowblossom.iceleaf.IceLeaf;
Expand Down Expand Up @@ -386,8 +387,11 @@ public void threadActionPerformed(ActionEvent e)
sb.append("Settings: " + ctx.block_ingestor.getHead().getEffectiveSettings());
}
sb.append(String.format("peers:%d ", ChannelLink.countActuallyOpen(ctx.getLinks())));
sb.append("\n");
sb.append(String.format("missing_chunks:%d", ChunkMapUtils.getWantList(ctx).size()));
sb.append("\n");
sb.append(String.format("outsiders:%s", ctx.db.getOutsiderMap().getByPrefix(ByteString.EMPTY, 500000, true).size()));
sb.append("\n");

sb.append("Peers:\n");
for(ChannelLink link : ctx.getLinks())
Expand Down
12 changes: 12 additions & 0 deletions src/warden/PremiumContentWarden.java
Expand Up @@ -7,20 +7,32 @@
import snowblossom.channels.proto.SignedMessage;

import snowblossom.channels.proto.ChannelBlock;
import com.google.protobuf.ByteString;

public class PremiumContentWarden extends BaseWarden
{
public PremiumContentWarden(ChannelAccess channel_access)
{
super(channel_access);




}

private SymmetricKey sym_key;

@Override
public void periodicRun() throws Exception
{
// Read encryption settings file
ByteString encryption_json_data = channel_access.readFile("/web/encryption.json");

// if exists, load sym key
// watch snow address
// on payments to address, compare to required amount
// if so, addKey for recipient


}

Expand Down
9 changes: 4 additions & 5 deletions test/CipherChannelTest.java
Expand Up @@ -2,10 +2,12 @@

import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import com.google.protobuf.util.JsonFormat;
import duckutil.ConfigMem;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
Expand All @@ -18,13 +20,10 @@
import org.junit.rules.TemporaryFolder;
import snowblossom.channels.*;
import snowblossom.channels.proto.*;
import snowblossom.channels.proto.EncryptedChannelConfig;
import snowblossom.lib.*;
import snowblossom.proto.WalletKeyPair;
import snowblossom.proto.AddressSpec;
import java.io.PrintStream;

import snowblossom.channels.proto.EncryptedChannelConfig;
import com.google.protobuf.util.JsonFormat;
import snowblossom.proto.WalletKeyPair;

public class CipherChannelTest
{
Expand Down

0 comments on commit 8449151

Please sign in to comment.