OutboundConnectionHandler(StreamsTransport transport, Address remoteAddress, EndPoint remoteSocketAddr)
        {
            var settings           = transport.Settings;
            var transmissionHandle =
                Source.ActorRef <Google.Protobuf.ByteString>(settings.BufferedMessages, OverflowStrategy.Backpressure);
            var fromLocalActors = FromProtobuf().Via(Encode(4, settings.MaxFrameSize, settings.ByteOrder));


            var fromRemoteActors = Decode(4, settings.MaxFrameSize, settings.ByteOrder).Via(ToProtobuf());

            var transmissionRef = transmissionHandle.PreMaterialize(transport.StreamMaterializer);

            var finalOutput = new RemoteOutboundAssociationSink(transport, remoteAddress, remoteSocketAddr, transmissionRef.Item1);

            var dsl = GraphDsl.Create(finalOutput, (builder, remoteOutput) =>
            {
                // local stages
                var localInput       = builder.Add(transmissionRef.Item2);
                var compilerCeremony = builder.Add(Flow.Create <Google.Protobuf.ByteString>());
                var local            = builder.Add(fromLocalActors);
                var merge            = builder.Add(new Merge <Google.Protobuf.ByteString, Google.Protobuf.ByteString>(2, false));
                builder.From(localInput.Outlet).To(merge.In(0));
                builder.From(compilerCeremony.Outlet).To(merge.In(1));
                builder.From(merge.Out).To(local.Inlet);

                // remote stages
                var remote = builder.Add(fromRemoteActors);
                builder.From(remote.Outlet).To(remoteOutput.Inlet);

                return(new BidiShape <ByteString, Google.Protobuf.ByteString, Google.Protobuf.ByteString, ByteString>(remote.Inlet, remote.Outlet, compilerCeremony.Inlet, local.Outlet));
            });

            return(BidiFlow.FromGraph(dsl));
        }
 public RemoteOutboundAssociationSink(StreamsTransport transport, Address remoteAddress, EndPoint localSocketAddress, IActorRef sourceRef)
 {
     _transport     = transport;
     _remoteAddress = remoteAddress;
     _localAddress  = localSocketAddress;
     _sourceRef     = sourceRef;
     Shape          = new SinkShape <Google.Protobuf.ByteString>(In);
 }
 public StreamsAssociationHandle(Address localAddress, Address remoteAddress, IActorRef streamsRef, StreamsTransport transport) : base(localAddress, remoteAddress)
 {
     _streamsRef = streamsRef;
     _transport  = transport;
 }
 private static AssociationHandle CreateAssociationHandle(StreamsTransport transport, IActorRef sourceRef,
                                                          Address localAddress, Address remoteAddress)
 {
     return(new StreamsAssociationHandle(localAddress, remoteAddress, sourceRef, transport));
 }