/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redPandaLib.core;
import crypt.Utils;
import java.nio.ByteBuffer;
import java.sql.Connection;
import java.util.HashMap;
import org.redPandaLib.Main;
import org.redPandaLib.NewMessageListener;
import org.redPandaLib.SpecialChannels;
import org.redPandaLib.core.messages.InfoMsg;
import static org.redPandaLib.core.messages.InfoMsg.BYTE;
import org.redPandaLib.core.messages.RawMsg;
import org.redPandaLib.core.messages.TextMessageContent;
import org.redPandaLib.core.messages.TextMsg;
import org.redPandaLib.crypt.ECKey;
/**
*
* @author rflohr
*/
public class KnownChannels {
public static void updateMyChannels() {
//remove all levels added by me to update...
Test.messageStore.removeKnownChannelFromIdenity(Test.localSettings.identity);
for (Channel channel : Test.getChannels()) {
//not for special channels...
if (channel.id < 0) {
continue;
}
int database_channel_id = Test.messageStore.getPubkeyId(channel.key);
Test.messageStore.addKnownChannel(database_channel_id, Test.localSettings.identity, -1, 0);
}
}
public static void sendAllKnownChannels() {
HashMap<ECKey, Integer> allKnownChannels = Test.messageStore.getAllKnownChannels();
System.out.println("KNWON CHANNELS: " + allKnownChannels.size());
byte[] myChannelsAsCommand = new byte[1 + 8 + (33 + 4) * allKnownChannels.size()];
ByteBuffer wrap = ByteBuffer.wrap(myChannelsAsCommand);
wrap.put(InfoMsg.BYTE);
wrap.putLong(Test.localSettings.identity);
for (ECKey key : allKnownChannels.keySet()) {
int level = allKnownChannels.get(key);
System.out.println("key: " + Utils.bytesToHexString(key.getPubKey()) + " lvl: " + level);
wrap.put(key.getPubKey());
wrap.putInt(level);
}
System.out.println("generated bytes...");
System.out.println("SEND channel levels to channel kb: " + myChannelsAsCommand.length / 1024.);
int cnt = 0;
//send
for (Channel channel : Test.getChannels()) {
cnt++;
//not for special channels...
if (channel.id < 0) {
continue;
}
InfoMsg build = InfoMsg.build(channel, System.currentTimeMillis(), 1234, myChannelsAsCommand);
RawMsg addMessage = MessageHolder.addMessage(build);
Test.broadcastMsg(addMessage);
//System.out.println("SENT channel levels to channel: " + Utils.bytesToHexString(myChannelsAsCommand));
}
System.out.println("send to all channels: " + cnt);
}
}