/** * Look for received packets and invoke receive. Mark them to be sent if returned with len!=0 from * TcpIp layer. */ public void run() { Packet p; PacketQueue rxQ = ejip.llRxQueue; if (rxQ == null) { if (Logging.LOG) Logging.wr("No link layer registered"); return; } // get one received packet from the receive queue p = rxQ.deq(); if (p != null) { receive(p); } else { udp.run(); if (Ejip.TCP_ENABLED) tcp.run(); } }
@Test public void materializedValues() throws Exception { // #mat-combine-1 // Materializes to Promise<BoxedUnit> (red) final Source<Integer, CompletableFuture<Optional<Integer>>> source = Source.<Integer>maybe(); // Materializes to BoxedUnit (black) final Flow<Integer, Integer, NotUsed> flow1 = Flow.of(Integer.class).take(100); // Materializes to Promise<Option<>> (red) final Source<Integer, CompletableFuture<Optional<Integer>>> nestedSource = source.viaMat(flow1, Keep.left()).named("nestedSource"); // #mat-combine-1 // #mat-combine-2 // Materializes to BoxedUnit (orange) final Flow<Integer, ByteString, NotUsed> flow2 = Flow.of(Integer.class).map(i -> ByteString.fromString(i.toString())); // Materializes to Future<OutgoingConnection> (yellow) final Flow<ByteString, ByteString, CompletionStage<OutgoingConnection>> flow3 = Tcp.get(system).outgoingConnection("localhost", 8080); // Materializes to Future<OutgoingConnection> (yellow) final Flow<Integer, ByteString, CompletionStage<OutgoingConnection>> nestedFlow = flow2.viaMat(flow3, Keep.right()).named("nestedFlow"); // #mat-combine-2 // #mat-combine-3 // Materializes to Future<String> (green) final Sink<ByteString, CompletionStage<String>> sink = Sink.<String, ByteString>fold("", (acc, i) -> acc + i.utf8String()); // Materializes to Pair<Future<OutgoingConnection>, Future<String>> (blue) final Sink<Integer, Pair<CompletionStage<OutgoingConnection>, CompletionStage<String>>> nestedSink = nestedFlow.toMat(sink, Keep.both()); // #mat-combine-3 // #mat-combine-4b // Materializes to Future<MyClass> (purple) final RunnableGraph<CompletionStage<MyClass>> runnableGraph = nestedSource.toMat(nestedSink, Combiner::f); // #mat-combine-4b }
/** * Process one IP packet. Change buffer and set length to get a packet sent back. called from * Net.loop(). */ public void receive(Packet p) { int i; int[] buf = p.buf; int len; i = buf[0]; len = i & 0xffff; // length from IP header // NO options are assumed in ICMP/TCP/IP... // => copy if options present // but we just drop it now - too lazy if (len > p.len || (i >>> 24 != 0x45)) { if (Logging.LOG) Logging.wr("IP options -> discard"); ejip.returnPacket(p); // packet to short or ip options => drop it return; } else { p.len = len; // correct for to long packets } // TODO fragmentation if (Ip.chkSum(buf, 0, 20) != 0) { ejip.returnPacket(p); if (Logging.LOG) Logging.wr("wrong IP checksum "); return; } int prot = (buf[2] >> 16) & 0xff; // protocol if (prot == PROT_ICMP) { doICMP(p); ip.doIp(p, prot); } else if (prot == Tcp.PROTOCOL) { if (Ejip.TCP_ENABLED) { // that's the new TCP processing tcp.process(p); } else { ejip.returnPacket(p); // mark packet free } } else if (prot == Udp.PROTOCOL) { udp.process(p); // Udp generates the reply } else { ejip.returnPacket(p); // mark packet free } }