コード例 #1
0
 private void send(Connection c, String message, int fromNode, int toNode) {
   int drop = rand.nextInt(100);
   if (drop >= links.getDropRate() || links.getDropRate() == 0) {
     String content = message;
     // TODO Change to only allowed matched responses.
     boolean shouldSend =
         (links.getOffset() == 0)
             || (!links.isCheckwhois())
             || ((content.length() > 12)
                 && (content.substring(0, 12).equals("WHOIS(Query,")
                     || content.subSequence(0, 13).equals("WHOIS(Answer,")));
     if (shouldSend) {
       // Corruption
       int corr = rand.nextInt(100);
       if (corr < links.getCorruptionRate()) {
         content = Texts.corrupt(content);
       }
       // Network delay
       int delay = (links.getDelay() > 0) ? rand.nextInt(links.getDelay()) : 0;
       synchronized (queue) {
         queue.add(new PacketMessage(c, delay, fromNode, toNode, content));
       }
     }
   }
 }