Changeset 0519ea4
- Timestamp:
- Nov 27, 2015 5:34:36 PM (5 years ago)
- Branches:
- master
- Children:
- 3a25a91
- Parents:
- 48d7f49
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java
r48d7f49 r0519ea4 1 1 package net.i2p.sam.client; 2 2 3 import java.io.ByteArrayInputStream; 3 4 import java.io.File; 4 5 import java.io.FileOutputStream; … … 6 7 import java.io.InputStream; 7 8 import java.io.OutputStream; 9 import java.net.DatagramPacket; 10 import java.net.DatagramSocket; 8 11 import java.net.Socket; 9 12 import java.security.GeneralSecurityException; … … 52 55 " -s: use SSL\n" + 53 56 " multiple -o session options are allowed"; 57 private static final int V3DGPORT=9999; 54 58 55 59 public static void main(String args[]) { … … 177 181 if (_log.shouldLog(Log.DEBUG)) 178 182 _log.debug("Handshake2 complete."); 183 } else if (_isV3 && (mode == DG || mode == RAW)) { 184 // set up a listening DatagramSocket 185 (new DGRcvr(mode)).start(); 179 186 } 180 187 writeDest(ourDest); 181 188 } catch (IOException e) { 182 189 _log.error("Unable to connect to SAM at " + _samHost + ":" + _samPort, e); 190 } 191 } 192 193 private class DGRcvr extends I2PAppThread { 194 private final int _mode; 195 196 public DGRcvr(int mode) { _mode = mode; } 197 198 public void run() { 199 byte[] buf = new byte[32768]; 200 try { 201 Sink sink = new Sink("FAKE", "FAKEFROM"); 202 DatagramSocket dg = new DatagramSocket(V3DGPORT); 203 while (true) { 204 DatagramPacket p = new DatagramPacket(buf, 32768); 205 dg.receive(p); 206 int len = p.getLength(); 207 int off = p.getOffset(); 208 byte[] data = p.getData(); 209 _log.info("Got datagram length " + len); 210 if (_mode == DG) { 211 ByteArrayInputStream bais = new ByteArrayInputStream(data, off, len); 212 String line = DataHelper.readLine(bais); 213 if (line == null) { 214 _log.error("DGRcvr no header line"); 215 continue; 216 } 217 if (line.length() < 516) { 218 _log.error("DGRcvr line too short: \"" + line + '\n'); 219 continue; 220 } 221 String[] parts = line.split(" "); 222 String dest = parts[0]; 223 _log.info("DG is from " + dest); 224 for (int i = 1; i < parts.length; i++) { 225 _log.info("Parameter: " + parts[i]); 226 } 227 int left = bais.available(); 228 sink.received(data, off + len - left, left); 229 } else { 230 sink.received(data, off, len); 231 } 232 } 233 } catch (IOException ioe) { 234 _log.error("DGRcvr", ioe); 235 } 183 236 } 184 237 } … … 472 525 if (mode == STREAM) 473 526 style = "STREAM"; 474 else if (mode == DG || mode ==V1DG)527 else if (mode == V1DG) 475 528 style = "DATAGRAM"; 529 else if (mode == DG) 530 style = "DATAGRAM PORT=" + V3DGPORT; 531 else if (mode == V1RAW) 532 style = "RAW"; 476 533 else 477 style = "RAW ";534 style = "RAW PORT=" + V3DGPORT; 478 535 String req = "SESSION CREATE STYLE=" + style + " DESTINATION=" + dest + ' ' + _conOptions + ' ' + sopts + '\n'; 479 536 samOut.write(req.getBytes()); … … 502 559 if (_log.shouldInfo()) 503 560 _log.info(_destFile + " is located at " + destination); 504 if (mode != STREAM) {561 if (mode == V1DG || mode == V1RAW) { 505 562 // fake it so the sink starts 506 563 eventHandler.streamConnectedReceived(destination, "FAKE");
Note: See TracChangeset
for help on using the changeset viewer.