コード例 #1
0
        public static IBus CreateFakeBus(int busReceptionPort, string busName, PeerId busId, int directoryServicePort, string directoryServiceName,PeerId directoryServiceId, IAssemblyScanner assemblyScanner = null, IPeerConfiguration peerconfig = null, IContainer container = null)
        {
            container = container ?? new Container();
            return BusFactory.CreateBus(container, containerConfigurationExpression: ctx =>
            {
                ctx.For
                    <ZmqTransportConfiguration>()
                    .Use(
                        new DummyTransportConfig(
                            busReceptionPort));

                ctx.For
                    <IBusBootstrapperConfiguration
                        >().Use(new DummyBootstrapperConfig
                        {
                            DirectoryServiceEndpoint
                                =
                                "tcp://localhost:" +
                                directoryServicePort,
                            DirectoryServiceName
                                =
                                directoryServiceName,
                                DirectoryServiceId =  directoryServiceId

                        });

                ctx.For<IPeerConfiguration>().Use(
                   peerconfig ?? new DummyPeerConfig(busName,busId, null));

                ctx.For<IAssemblyScanner>().Use(
                    assemblyScanner ?? new AssemblyScanner());

            });
        }
コード例 #2
0
ファイル: LTChat.cs プロジェクト: burris/monotorrent
        internal override void Handle(PeerId id)
        {
            if (!ClientEngine.SupportsFastPeer)
                throw new MessageException("Libtorrent extension messages not supported");

            // FIXME: Do nothing for the moment - Maybe raise an event in the future?
        }
コード例 #3
0
ファイル: ZmqOutboundSocket.cs プロジェクト: MarouenK/Zebus
 public ZmqOutboundSocket(ZmqContext context, PeerId peerId, string endPoint, IZmqSocketOptions options)
 {
     _context = context;
     _peerId = peerId;
     _options = options;
     EndPoint = endPoint;
 }
コード例 #4
0
 public ServicePeer(string peerName, PeerId peerId, List<MessageSubscription> handledMessages, List<ShadowedPeerConfiguration> shadowedPeers)
 {
     PeerName = peerName;
     PeerId = peerId;
     HandledMessages = handledMessages;
     ShadowedPeers = shadowedPeers;
 }
コード例 #5
0
ファイル: OriginatorInfo.cs プロジェクト: MarouenK/Zebus
 public OriginatorInfo(PeerId senderId, string senderEndPoint, string senderMachineName, string initiatorUserName)
 {
     SenderId = senderId;
     SenderEndPoint = senderEndPoint;
     SenderMachineName = senderMachineName;
     InitiatorUserName = initiatorUserName;
 }
コード例 #6
0
ファイル: Peer.cs プロジェクト: MarouenK/Zebus
 public Peer(PeerId id, string endPoint, bool isUp, bool isResponding)
 {
     Id = id;
     EndPoint = endPoint;
     IsUp = isUp;
     IsResponding = isResponding;
 }
コード例 #7
0
ファイル: PeerDescriptor.cs プロジェクト: MarouenK/Zebus
 public PeerDescriptor(PeerId id, string endPoint, bool isPersistent, bool isUp, bool isResponding, DateTime timestampUtc, params Subscription[] subscriptions)
 {
     Peer = new Peer(id, endPoint, isUp, isResponding);
     Subscriptions = subscriptions;
     IsPersistent = isPersistent;
     TimestampUtc = timestampUtc;
 }
コード例 #8
0
 public MessageWireData(string messageType, Guid messageIdentity, PeerId sendingPeer, byte[] data)
 {
     MessageType = messageType;
     MessageIdentity = messageIdentity;
     Data = data;
     SendingPeerId = sendingPeer;
 }
コード例 #9
0
ファイル: Peer.cs プロジェクト: Dozey/Distribution2
 internal Peer(PeerId id, string hostNameOrAddress, int port)
 {
     _id = id;
     _ip = null;
     _hostNameOrAddress = hostNameOrAddress;
     _port = port;
 }
コード例 #10
0
 public ShadowMessageCommand(MessageWireData message, PeerId primaryRecipient, bool primaryWasOnline, IEndpoint targetEndpoint)
 {
     Message = message;
     PrimaryRecipient = primaryRecipient;
     PrimaryWasOnline = primaryWasOnline;
     TargetEndpoint = targetEndpoint;
 }
コード例 #11
0
        public void should_get_peer_id()
        {
            var peerId = new PeerId("Abc.Foo.0");
            _busMock.SetupGet(x => x.PeerId).Returns(peerId);

            _bus.PeerId.ShouldEqual(peerId);
        }
コード例 #12
0
ファイル: BusFactory.cs プロジェクト: MarouenK/Zebus
        public BusFactory(IContainer container)
        {
            PeerId = new PeerId("Abc.Testing." + Guid.NewGuid());

            _scanTargets.Add(new ScanTarget(typeof(IBus).Assembly, null));

            Container = container;
        }
コード例 #13
0
ファイル: ZmqInboundSocket.cs プロジェクト: MarouenK/Zebus
 public ZmqInboundSocket(ZmqContext context, PeerId peerId, ZmqEndPoint originalEndpoint, IZmqSocketOptions options, string environment)
 {
     _context = context;
     _peerId = peerId;
     _originalEndpoint = originalEndpoint;
     _options = options;
     _environment = environment;
 }
コード例 #14
0
 public void ResetSequenceNumbersForPeer(PeerId peer)
 {
     var keysToRemove = _sequenceNumber.Keys.Where(x => x.Peer == peer).ToList();
     foreach (var key in keysToRemove)
     {
         _sequenceNumber.Remove(key);
     }
 }
コード例 #15
0
 public MessageSubscription(Type messageType, PeerId peer, IEndpoint endpoint, ISubscriptionFilter subscriptionFilter, ReliabilityLevel reliabilityLevel)
 {
     MessageType = messageType;
     Peer = peer;
     Endpoint = endpoint;
     SubscriptionFilter = (subscriptionFilter);
     ReliabilityLevel = reliabilityLevel;
 }
コード例 #16
0
        internal static IAsyncResult BeginCheckEncryption(PeerId id, int bytesToReceive, AsyncCallback callback, object state, InfoHash[] sKeys)
        {
            EncryptorAsyncResult result = new EncryptorAsyncResult(id, callback, state);
            result.SKeys = sKeys;

            IConnection c = id.Connection;
            ClientEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(10), delegate {
                if (id.Encryptor == null || id.Decryptor == null)
                    id.CloseConnection();
                return false;
            });

            try
            {
                // If the connection is incoming, receive the handshake before
                // trying to decide what encryption to use
                if (id.Connection.IsIncoming)
                {
                    result.Buffer = new byte[bytesToReceive];
                    NetworkIO.EnqueueReceive(c, result.Buffer, 0, result.Buffer.Length, null, null, null, HandshakeReceivedCallback, result);
                }
                else
                {
                    EncryptionTypes usable = CheckRC4(id);
                    bool hasPlainText = Toolbox.HasEncryption(usable, EncryptionTypes.PlainText);
                    bool hasRC4 = Toolbox.HasEncryption(usable, EncryptionTypes.RC4Full) || Toolbox.HasEncryption(usable, EncryptionTypes.RC4Header);
                    if (id.Engine.Settings.PreferEncryption)
                    {
                        if (hasRC4)
                        {
                            result.EncSocket = new PeerAEncryption(id.TorrentManager.InfoHash, usable);
                            result.EncSocket.BeginHandshake(id.Connection, CompletedEncryptedHandshakeCallback, result);
                        }
                        else
                        {
                            result.Complete();
                        }
                    }
                    else
                    {
                        if (hasPlainText)
                        {
                            result.Complete();
                        }
                        else
                        {
                            result.EncSocket = new PeerAEncryption(id.TorrentManager.InfoHash, usable);
                            result.EncSocket.BeginHandshake(id.Connection, CompletedEncryptedHandshakeCallback, result);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Complete(ex);
            }
            return result;
        }
コード例 #17
0
ファイル: BusMessageLogger.cs プロジェクト: MarouenK/Zebus
        public void DebugFormat(string format, IMessage message, MessageId? messageId = null, int messageSize = 0, PeerId peerId = default(PeerId))
        {
            var logInfo = GetLogInfo(message);
            if (!logInfo.Logger.IsDebugEnabled)
                return;

            var messageText = logInfo.GetMessageText(message);
            _logger.DebugFormat(format, messageText, messageId, messageSize, peerId);
        }
コード例 #18
0
 public ShadowCompletionMessage(Guid messageId, PeerId fromPeer, PeerId toPeer, bool processingSuccessful, IEndpoint endpoint, string messageType)
 {
     MessageId = messageId;
     FromPeer = fromPeer;
     ToPeer = toPeer;
     ProcessingSuccessful = processingSuccessful;
     Endpoint = endpoint;
     MessageType = messageType;
 }
コード例 #19
0
 public ReceivedTransportMessage(string messageType, PeerId peerId, Guid messageIdentity, IEndpoint endpoint, byte[] data, int? sequenceNumber)
 {
     PeerId = peerId;
     MessageIdentity = messageIdentity;
     MessageType = messageType;
     Data = data;
     SequenceNumber = sequenceNumber;
     Endpoint = endpoint;
 }
コード例 #20
0
 public void Reinitialize(string messageType, PeerId peerId, Guid messageIdentity, IEndpoint endpoint, byte[] data, int? sequenceNumber)
 {
     PeerId = peerId;
     MessageIdentity = messageIdentity;
     MessageType = messageType;
     Data = data;
     SequenceNumber = sequenceNumber;
     Endpoint = endpoint;
 }
コード例 #21
0
        public void should_configure_bus()
        {
            var peerId = new PeerId("Abc.Foo.0");
            var environment = "Dev";

            _bus.Configure(peerId, environment);

            _busMock.Verify(x => x.Configure(peerId, environment));
        }
コード例 #22
0
 public static StorageSubscription ToStorageSubscription(this SubscriptionsForType subscriptionFortype, PeerId peerId)
 {
     return new StorageSubscription
     {
         PeerId = peerId.ToString(),
         MessageTypeId = subscriptionFortype.MessageTypeId.FullName,
         SubscriptionBindings = SerializeBindingKeys(subscriptionFortype.BindingKeys)
     };
 }
コード例 #23
0
        public void AddDynamicSubscriptionsForTypes(PeerId peerId, DateTime timestampUtc, SubscriptionsForType[] subscriptionsForTypes)
        {
            var peerEntry = GetEntry(peerId);
            if (peerEntry == null)
                return;
            if (!(timestampUtc >= peerEntry.PeerDescriptor.TimestampUtc))
                return;

            var subscriptions = subscriptionsForTypes.SelectMany(sub => sub.BindingKeys.Select(binding => new Subscription(sub.MessageTypeId, binding))).ToList();
            peerEntry.DynamicSubscriptions = peerEntry.DynamicSubscriptions.Concat(subscriptions).ToList();
        }
コード例 #24
0
 public IEnumerable<ShadowMessageCommand> GetFirstMessages(PeerId peer, IEndpoint endpoint, int maxCount)
 {
     PeerMessageQueue queue;
     if (!_savedMessages.TryGetValue(peer, out queue))
         yield break;
     int numberOfReturnedMessages = 0;
     while (queue[endpoint].Count != 0 && numberOfReturnedMessages < maxCount)
     {
         yield return queue[endpoint].Dequeue();
         numberOfReturnedMessages++;
     }
 }
コード例 #25
0
ファイル: LTChat.cs プロジェクト: burris/monotorrent
 public LTChat(PeerId peer, string message)
 {
     for (int i = 0; i < peer.ExtensionSupports.Count; i++)
     {
         if (peer.ExtensionSupports[i].Name != Support.Name)
             continue;
         MessageId = peer.ExtensionSupports[i].MessageId;
         Message = message;
         return;
     }
     throw new MessageException("The peer does not support chat messages");
 }
コード例 #26
0
        public static bool SetPeerRespondingState(this IPeerRepository repository, PeerId peerId, bool isResponding, DateTime timestampUtc)
        {
            var peer = repository.Get(peerId);
            if (peer == null || peer.TimestampUtc > timestampUtc)
                return false;

            peer.Peer.IsResponding = isResponding;
            peer.TimestampUtc = timestampUtc;
            repository.AddOrUpdatePeer(peer);

            return true;
        }
コード例 #27
0
ファイル: SerializationTests.cs プロジェクト: MarouenK/Zebus
        public void should_convert_peer_id_to_json_string()
        {
            var peerId = new PeerId("Abc.Testing.42");
            var text = JsonConvert.SerializeObject(new MessageWithPeerId { PeerId1 =  peerId });

            text.ShouldContain(peerId.ToString());

            Console.WriteLine(text);

            var message = JsonConvert.DeserializeObject<MessageWithPeerId>(text);
            message.PeerId1.ShouldEqual(peerId);
            message.PeerId2.ShouldBeNull();
        }
コード例 #28
0
ファイル: MessageContext.cs プロジェクト: MarouenK/Zebus
        public static MessageContext CreateOverride(PeerId peerId, string peerEndPoint)
        {
            var currentContext = Current;
            var initiatorUserName = GetInitiatorUserName();

            var originator = new OriginatorInfo(peerId, peerEndPoint, CurrentMachineName, initiatorUserName);

            return new MessageContext
            {
                MessageId = MessageId.NextId(),
                Originator = originator,
                DispatchQueueName = currentContext?.DispatchQueueName,
            };
        }
コード例 #29
0
        private static EncryptionTypes CheckRC4(PeerId id)
        {
            // If the connection is *not* incoming, then it will be associated with an Engine
            // so we can check what encryption levels the engine allows.
            EncryptionTypes t;
            if (id.Connection.IsIncoming)
                t = EncryptionTypes.All;
            else
                t = id.TorrentManager.Engine.Settings.AllowedEncryption;

            // We're allowed use encryption if the engine settings allow it and the peer supports it
            // Binary AND both the engine encryption and peer encryption and check what levels are supported
            t &= id.Peer.Encryption;
            return t;
        }
コード例 #30
0
        public static PeerDescriptor UpdatePeerSubscriptions(this IPeerRepository repository, PeerId peerId, Subscription[] subscriptions, DateTime? timestampUtc)
        {
            var peerDescriptor = repository.Get(peerId);
            if (peerDescriptor == null)
                throw new InvalidOperationException(string.Format("The specified Peer ({0}) does not exist.", peerId));

            if (peerDescriptor.TimestampUtc > timestampUtc)
                return null;

            peerDescriptor.TimestampUtc = timestampUtc;
            peerDescriptor.Subscriptions = subscriptions;
            repository.AddOrUpdatePeer(peerDescriptor);

            return peerDescriptor;
        }
コード例 #31
0
 public SubscriptionsUpdated(Subscription subscription, PeerId peerId)
 {
     Subscriptions = new SubscriptionsForType(subscription.MessageTypeId, subscription.BindingKey);
     PeerId        = peerId;
 }
コード例 #32
0
 protected override void HandleResponse(SetPeerBlacklistResponse setPeerBlackListResponse,
                                        IChannelHandlerContext channelHandlerContext,
                                        PeerId senderPeerIdentifier,
                                        ICorrelationId correlationId)
 {
 }
コード例 #33
0
 public SubscriptionsUpdated(SubscriptionsForType subscriptions, PeerId peerId)
 {
     Subscriptions = subscriptions;
     PeerId        = peerId;
 }