use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.
the class Channel2Client method main.
public static void main(String[] args) throws Exception {
if (args.length < parameterNum) {
System.out.println("param: target topic total number of request");
return;
}
String topic = args[0];
Integer count = Integer.parseInt(args[1]);
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
logger.debug("init client");
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
System.out.println("3s ...");
Thread.sleep(1000);
System.out.println("2s ...");
Thread.sleep(1000);
System.out.println("1s ...");
Thread.sleep(1000);
System.out.println("start test");
System.out.println("===================================================================");
ChannelRequest request = new ChannelRequest();
for (Integer i = 0; i < count; ++i) {
Thread.sleep(2000);
request.setToTopic(topic);
request.setMessageID(service.newSeq());
request.setTimeout(5000);
String content = "request seq:" + request.getMessageID();
request.setContent(content.getBytes());
System.out.println(df.format(LocalDateTime.now()) + " request seq:" + request.getMessageID() + ", Content:" + request.getContent() + " content:" + Arrays.toString(request.getContentByteArray()));
ChannelResponse response = service.sendChannelMessage2(request);
System.out.println(df.format(LocalDateTime.now()) + "response seq:" + response.getMessageID() + ", ErrorCode:" + response.getErrorCode() + ", Content:" + response.getContent());
}
}
use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.
the class Channel2ClientBinNeedVerify method main.
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("param: target topic filename of request");
return;
}
String topic = args[0];
String filename = args[1];
Integer count = 10;
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
logger.debug("init client");
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
System.out.println("3s ...");
Thread.sleep(1000);
System.out.println("2s ...");
Thread.sleep(1000);
System.out.println("1s ...");
Thread.sleep(1000);
System.out.println("start test");
System.out.println("===================================================================");
for (Integer i = 0; i < count; ++i) {
Thread.sleep(2000);
ChannelRequest request = new ChannelRequest();
request.setToTopic(topic);
request.setMessageID(service.newSeq());
request.setTimeout(5000);
/*设置为-128表示为传输二进制*/
int flag = -128;
byte[] byteflag = intToByteArray(flag);
int filelength = filename.length();
byte[] bytelength = intToByteArray(filelength);
byte[] bytefilename = filename.getBytes();
byte[] contentfile = toByteArrFromFile(filename);
byte[] content = byteCat(byteCat(byteCat(byteflag, bytelength), bytefilename), contentfile);
request.setContent(content);
logger.info("msg:" + Arrays.toString(content));
System.out.println(df.format(LocalDateTime.now()) + " request seq:" + String.valueOf(request.getMessageID()) + " content length:" + content.length);
ChannelResponse response = service.sendChannelMessageForVerifyTopic(request);
System.out.println(df.format(LocalDateTime.now()) + "response seq:" + String.valueOf(response.getMessageID()) + ", ErrorCode:" + response.getErrorCode() + ", Content:" + response.getContent());
if (response.getErrorCode() != 0) {
System.out.println("Error message" + response.getErrorMessage());
}
}
}
use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.
the class Channel2ClientMultiNeedVerify method main.
public static void main(String[] args) throws Exception {
if (args.length < parameterNum) {
System.out.println("param: target topic total number of request");
return;
}
String topic = args[0];
Integer count = Integer.parseInt(args[1]);
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
logger.debug("init client");
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
System.out.println("3s ...");
Thread.sleep(1000);
System.out.println("2s ...");
Thread.sleep(1000);
System.out.println("1s ...");
Thread.sleep(1000);
System.out.println("start test");
System.out.println("===================================================================");
for (Integer i = 0; i < count; ++i) {
Thread.sleep(2000);
ChannelRequest request = new ChannelRequest();
request.setToTopic(topic);
request.setMessageID(service.newSeq());
request.setTimeout(5000);
request.setContent("request seq:" + request.getMessageID());
System.out.println(df.format(LocalDateTime.now()) + " multicast request seq:" + String.valueOf(request.getMessageID()) + ", Content:" + request.getContent());
service.asyncMulticastChannelMessageForVerifyTopic(request);
}
}
use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.
the class Service method checkTopicVerify.
public void checkTopicVerify(ChannelHandlerContext ctx, TopicVerifyMessage message) throws IOException {
SocketChannel socketChannel = (SocketChannel) ctx.channel();
logger.info("get rand value request ChannelResponse seq:{} msgtype:{} address:{} port:{}", message.getSeq(), message.getType(), socketChannel.remoteAddress().getAddress().getHostAddress(), socketChannel.remoteAddress().getPort());
logger.info("get rand value request :{} length:{}", Arrays.toString(message.getData()), message.getLength());
sendResponse2Node(ctx, message);
String content = new String(message.getData());
logger.info("content:{} content:{}", content, Arrays.toString(content.getBytes()));
NodeRequestSdkVerifyTopic nodeRequestSdkVerifyTopic = ObjectMapperFactory.getObjectMapper().readValue(content, NodeRequestSdkVerifyTopic.class);
String topic = nodeRequestSdkVerifyTopic.getTopic();
String topicForCert = nodeRequestSdkVerifyTopic.getTopicForCert();
String nodeid = nodeRequestSdkVerifyTopic.getNodeId();
logger.info("topic:{} topicForCert:{} nodeid:{}", topic, topicForCert, nodeid);
ChannelRequest request = new ChannelRequest();
request.setToTopic(topicForCert);
request.setMessageID(newSeq());
request.setTimeout(5000);
request.setType((short) ChannelMessageType.AMOP_REQUEST.getType());
String randValue = UUID.randomUUID().toString().replaceAll("-", "");
TopicVerifyReqProtocol topicVerifyProtocol = new TopicVerifyReqProtocol();
topicVerifyProtocol.setRandValue(randValue);
topicVerifyProtocol.setTopic(topic);
String jsonStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(topicVerifyProtocol);
logger.info("generate rand value jsonStr:{} topic:{} messageid:{}", jsonStr, request.getToTopic(), message.getSeq());
byte[] bytes = topicVerify.getByteBuffByString(request.getToTopic(), jsonStr);
request.setContent(bytes);
asyncSendChannelMessage2(request, new ChannelResponseCallback2() {
@Override
public void onResponseMessage(ChannelResponse response) {
logger.info("get response messageid:{}", response.getMessageID());
try {
checkSignForAmop(topic, String.valueOf(randValue), nodeid, ctx, response);
} catch (IOException e) {
logger.error("check sign for amop failed:{}", e);
}
}
});
}
use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.
the class Channel2ClientMultiBin method main.
public static void main(String[] args) throws Exception {
if (args.length < parameterNum) {
System.out.println("param: target topic total number of request");
return;
}
String topic = args[0];
Integer count = 1;
String filename = args[1];
int flag = -128;
byte[] byteflag = Channel2ClientBin.intToByteArray(flag);
int filelength = filename.length();
byte[] bytelength = Channel2ClientBin.intToByteArray(filelength);
byte[] bytefilename = filename.getBytes();
byte[] contentfile = Channel2ClientBin.toByteArrFromFile(filename);
byte[] content = Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(byteflag, bytelength), bytefilename), contentfile);
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
logger.debug("init client");
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
System.out.println("3s ...");
Thread.sleep(1000);
System.out.println("2s ...");
Thread.sleep(1000);
System.out.println("1s ...");
Thread.sleep(1000);
System.out.println("start test");
System.out.println("===================================================================");
for (Integer i = 0; i < count; ++i) {
Thread.sleep(2000);
ChannelRequest request = new ChannelRequest();
request.setToTopic(topic);
request.setMessageID(service.newSeq());
request.setTimeout(5000);
request.setContent(content);
System.out.println(df.format(LocalDateTime.now()) + " multicast request seq:" + String.valueOf(request.getMessageID()) + ", filename:" + filename);
service.asyncMulticastChannelMessage2(request);
}
}
Aggregations