public static TChannel OpenPeerChannel <TService, TChannel>() where TChannel : IClientChannel { var portnumber = DeNSo.Configuration.Extensions.P2P().NetworkPort; NetPeerTcpBinding binding = new NetPeerTcpBinding() { Port = portnumber, Name = GetURI().OriginalString + "@" + portnumber, }; binding.Security.Mode = SecurityMode.None; EndpointAddress address = new EndpointAddress(GetURI().OriginalString); ChannelFactory <TChannel> sourceFactory = new ChannelFactory <TChannel>(binding, address); //sourceFactory.Credentials.Peer.MeshPassword = DeNSo.Configuration.Extensions.P2P().NetworkPassword; TChannel sourceProxy = (TChannel)sourceFactory.CreateChannel(); MessagePropagationFilter remoteOnlyFilter = new MessagePropagationFilter(); PeerNode peerNode = ((IClientChannel)sourceProxy).GetProperty <PeerNode>(); //peerNode.MessagePropagationFilter = remoteOnlyFilter; sourceProxy.Open(); return(sourceProxy); }
internal override IList <TransportManager> SelectTransportManagers() { //test override if (peerNode == null) { PeerNodeImplementation foundPeerNode = null; // use the private InnerNode if it has been configured and matches the channel if (privatePeerNode != null && this.Uri.Host == privatePeerNode.MeshId) { foundPeerNode = privatePeerNode; this.registration = null; } else { // find or create a InnerNode for the given Uri this.registration = new PeerNodeImplementation.Registration(this.Uri, this); foundPeerNode = PeerNodeImplementation.Get(this.Uri, registration); } // ensure that the max message size is compatible if (foundPeerNode.MaxReceivedMessageSize < MaxReceivedMessageSize) { foundPeerNode.Release(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR.GetString(SR.PeerMaxReceivedMessageSizeConflict, MaxReceivedMessageSize, foundPeerNode.MaxReceivedMessageSize, this.Uri))); } // associate with the PeerNode and open it peerNode = new PeerNode(foundPeerNode); } return(null); }
/// <summary> /// Add a new peer node to <c>this.peerNodes</c>. The /// <c>cntResponseChances</c> of the new node is set to /// <c>this.cntResponseChances</c>. If the node is already known, its /// <c>cntResponeChances</c> counter is reset. /// /// If the node is new, the <c>NodeFound</c> event is /// fired by this method. /// </summary> /// <param name="address"></param> /// <param name="peerAddr"></param> protected void addPeerNode(SocketAddress address, EndPoint peerAddr) { NodeFoundHandler evt = this.NodeFound; PeerNode peerNode = null; /* Add to collection. */ lock (this.peerNodes) { peerNode = this.peerNodes.Find(delegate(PeerNode p) { return(p.Address.Equals(address)); }); if (peerNode != null) { /* Node alredy known, reset response counter. */ Debug.WriteLine("Node " + address.ToString() + "(" + peerAddr.ToString() + ") is already known."); peerNode.cntResponseChances = this.cntResponseChances; } else { /* This is a new node, add it and fire event. */ Debug.WriteLine("Node " + address.ToString() + "(" + peerAddr.ToString() + ") added."); peerNode = new PeerNode(address, (IPEndPoint)peerAddr, this.cntResponseChances); this.peerNodes.Add(peerNode); if (evt != null) { evt(this, peerNode); } } /* end if (peerNode != null) */ } /* end lock (this.peerNodes) */ }
public void GetPacsNodeParametersByAETest() { //PrivateType type = new PrivateType(typeof(Printers)); //Class1为要测试的类。 //PrivateObject privateObj = new PrivateObject(Printers.Instance, type); //Printers_Accessor target = new Printers_Accessor(privateObj); Printers target = Printers.Instance; string sNodeAE = "LEAD_SERVER"; // var peerNode = new PeerNode(); var peerNodeExpected = new PeerNode { PeerAE = "LEAD_SERVER", PeerIP = "10.1.3.194", PeerPort = 10006 }; int expected = 0; int actual; //actual = target.GetPacsNodeParametersByAE(sNodeAE, ref peerNode); //Assert.AreEqual(peerNodeExpected.PeerAE,peerNode.PeerAE); //Assert.AreEqual(peerNodeExpected.PeerIP,peerNode.PeerIP); //Assert.AreEqual(peerNodeExpected.PeerPort,peerNode.PeerPort); //Assert.AreEqual(expected, actual); sNodeAE = "aa"; peerNode = new PeerNode(); actual = target.GetPacsNodeParametersByAE(sNodeAE, ref peerNode); expected = -1; Assert.AreEqual(expected, actual); }
public PeerDuplexChannel(IPeerChannelManager listener) : base((ChannelListenerBase)listener) { binding = listener.Source; this.resolver = listener.Resolver; info = new TcpChannelInfo(binding, listener.MessageEncoder, null); // FIXME: fill properties correctly. node = new PeerNodeImpl(((ChannelListenerBase)listener).Uri.Host, listener.Source.ListenIPAddress, listener.Source.Port); }
public void AllowAutoFilmingTest() { var target = new PeerNode(); // bool actual; target.AllowAutoFilming = true; actual = target.AllowAutoFilming; Assert.AreEqual(true, actual); }
public void PrinterDiscriptionTest() { PeerNode target = new PeerNode(); // string expected = "aa"; // string actual; target.PrinterDiscription = expected; actual = target.PrinterDiscription; Assert.AreEqual(expected, actual); }
public void PeerPortTest() { PeerNode target = new PeerNode(); // ushort expected = 2; // ushort actual; target.PeerPort = expected; actual = target.PeerPort; Assert.AreEqual(expected, actual); }
public PeerOutputChannel(PeerChannelFactory <IOutputChannel> factory, EndpointAddress address, Uri via, PeerResolver resolver) : base(factory, address, via) { this.factory = factory; this.resolver = resolver; // It could be opened even with empty list of PeerNodeAddresses. // So, do not create PeerNode per PeerNodeAddress, but do it with PeerNodeAddress[]. node = new PeerNodeImpl(resolver, RemoteAddress, factory.Source.Port); }
public void PeerIPTest() { PeerNode target = new PeerNode(); // string expected = "aa"; // string actual; target.PeerIP = expected; actual = target.PeerIP; Assert.AreEqual(expected, actual); }
public void PeerTest() { JobCreator target = new JobCreator(); PeerNode expected = null; PeerNode actual; target.Peer = expected; actual = target.Peer; Assert.AreEqual(expected, actual); }
private void InitiateChannel(IChannel initiatedChannel) { initiatedChannel.Closed += (s, e) => { var handler = Closed; if (handler == null) { return; } handler(s, e); }; initiatedChannel.Closing += (s, e) => { var handler = Closing; if (handler == null) { return; } handler(s, e); }; initiatedChannel.Faulted += (s, e) => { var handler = Faulted; if (handler == null) { return; } handler(s, e); }; initiatedChannel.Opened += (s, e) => { openedStateResetEvent.Set(); var handler = Opened; if (handler == null) { return; } handler(s, e); }; initiatedChannel.Opening += (s, e) => { openedStateResetEvent.Reset(); var handler = Opening; if (handler == null) { return; } handler(s, e); }; PeerNode = initiatedChannel.GetProperty <PeerNode>(); }
public void DefaultOrientationTest() { PeerNodeType type = new PeerNodeType(); PeerNode target = new PeerNode(type); int expected = 0; int actual; target.DefaultOrientation = expected; actual = target.DefaultOrientation; Assert.AreEqual(expected, actual); }
public void DefaultFilmSizeTest() { PeerNodeType type = new PeerNodeType(); PeerNode target = new PeerNode(type); string expected = string.Empty; string actual; target.DefaultFilmSize = expected; actual = target.DefaultFilmSize; Assert.AreEqual(expected, actual); }
public void MaxDensityTest() { PeerNodeType type = new PeerNodeType(); PeerNode target = new PeerNode(type); int expected = 0; int actual; target.MaxDensity = expected; actual = target.MaxDensity; Assert.AreEqual(expected, actual); }
public PeerInputChannel(PeerNodeImplementation peerNode, PeerNodeImplementation.Registration registration, ChannelManagerBase channelManager, EndpointAddress localAddress, Uri via) : base(channelManager, localAddress) { PeerNodeImplementation.ValidateVia(via); if (registration != null) { peerNode = PeerNodeImplementation.Get(via, registration); } this.peerNode = new PeerNode(peerNode); this.to = localAddress; this.via = via; }
public PeerDuplexChannel(IPeerChannelManager factory, EndpointAddress address, Uri via, PeerResolver resolver) : base((ChannelFactoryBase)factory, address, via) { binding = factory.Source; this.resolver = factory.Resolver; info = new TcpChannelInfo(binding, factory.MessageEncoder, null); // FIXME: fill properties correctly. // It could be opened even with empty list of PeerNodeAddresses. // So, do not create PeerNode per PeerNodeAddress, but do it with PeerNodeAddress[]. node = new PeerNodeImpl(RemoteAddress.Uri.Host, factory.Source.ListenIPAddress, factory.Source.Port); }
public void NodeTypeTest() { PeerNodeType type = new PeerNodeType(); PeerNode target = new PeerNode(type); PeerNodeType expected = new PeerNodeType(); PeerNodeType actual; target.NodeType = expected; actual = target.NodeType; Assert.AreEqual(expected, actual); }
public PeerOutputChannel(PeerNodeImplementation peerNode, PeerNodeImplementation.Registration registration, ChannelManagerBase channelManager, EndpointAddress localAddress, Uri via, MessageVersion messageVersion) : base(channelManager, localAddress, via, false, messageVersion) { PeerNodeImplementation.ValidateVia(via); if (registration != null) { peerNode = PeerNodeImplementation.Get(via, registration); } this.peerNode = new PeerNode(peerNode); this.via = via; this.channelManager = channelManager; this.to = localAddress; }
public PeerNode Save(PeerNode n) { using (dbc = DAL.Instance.GetDb()){ n.Id = (uint)IdManager.GetId(); n.CreationDate = DateTime.Now; //n.Generation = 0; dbc.Insert(n); //return (long)dbc.GetLastInsertId(); //return person.Id; } return(n); }
public void SupportFilmSizeListTest() { PeerNode target = new PeerNode(); // List <object> expected = new List <object>(); expected.Add("aa"); expected.Add("bb");// List <object> actual; target.SupportFilmSizeList = expected; actual = target.SupportFilmSizeList; Assert.AreEqual(expected, actual); }
public void SupportLayoutListTest() { PeerNode target = new PeerNode(); // List <string> expected = new List <string>(); expected.Add("aa"); expected.Add("bb");// List <string> actual; target.SupportLayoutList = expected; actual = target.SupportLayoutList; Assert.AreEqual(expected, actual); }
internal PeerNode NodeApproved(byte[] certSerial) { NodeCertificate nc = new CertificateDAO().GetBySerial(certSerial); if (nc == null) { return(null); } PeerNode n = GetPeerNode(nc.NodeId); n.Certificate = nc; n.PublicKey = nc.PublicKey; return(n); }
public void ToStringTest() { var target = new PeerNode(); target.PrinterDiscription = "aa"; target.PeerAE = "bb"; target.PeerIP = "cc"; target.PeerPort = 2; string expected = "aa's AE:bb;IP:cc;Port:2"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
/// <summary> /// Метод, создающий транзакцию, подтверждающий ее и добавляющий в список подтвержденных в этом и соседнем узлах /// </summary> public void TransactionSynch() { Transaction newTransaction = CreateNewTransaction(10.00m + (differentiation_amount++)); PeerNode.ValidateTransaction(newTransaction); ValidateTransaction(newTransaction); if (newTransaction.ConfirmationsCount > 1) { newTransaction.IsConfirmed = true; } if (newTransaction.IsConfirmed == true) { ConfirmedTransactions.Add(newTransaction); PeerNode.ConfirmedTransactions.Add(newTransaction); } }
/// <summary> /// Метод, майнит блок, подтверждает его у соседа и у себя и если подтвержден, то добавит блок /// в предварительный список блоков блокчейна для последующего выбора /// блока, который будет присоединен (на основании времени майнинга) /// </summary> public void AddConfirmedBlockToPendingBlocks() { Block newBlock = MineBlock(); if (newBlock != null) { PeerNode.ValidateBlock(newBlock); ValidateBlock(newBlock); if (newBlock.ConfirmationsCount > 1) { newBlock.IsConfirmed = true; } if (newBlock.IsConfirmed) { PendingConfirmedBlocks.Add(newBlock); PeerNode.PendingConfirmedBlocks.Add(newBlock); } } }
protected void fireUserMessage(EndPoint peerAddr, UInt32 msgType, byte[] msgBody, uint bodyOffset) { UserMessageHandler evt = this.UserMessage; IPEndPoint addr = peerAddr as IPEndPoint; Debug.WriteLine("Firing user message notification ..."); if ((addr != null) && (evt != null)) { PeerNode peerNode = this.peerFromDiscoveryAddr(addr); if ((peerNode != null)) { byte[] body = new byte[MAX_USER_DATA]; Array.Copy(msgBody, bodyOffset, body, 0, MAX_USER_DATA); evt(this, peerNode, msgType, body); } } }
private void RegisterProxyEvent(ChannelWrapper registeredChannel) { registeredChannel.Closing += InvokeCommunicationStateChanged; registeredChannel.Closed += InvokeCommunicationStateChanged; registeredChannel.Faulted += InvokeCommunicationStateChanged; registeredChannel.Opened += InvokeCommunicationStateChanged; registeredChannel.Opening += InvokeCommunicationStateChanged; peerNode = registeredChannel.GetProperty <PeerNode>(); if (peerNode == null) { throw new InvalidOperationException("incorrect behavior - peerNode is null"); } peerNode.Online += (o, e) => InvokePeerOnline(e); peerNode.Offline += (o, e) => InvokePeerOffline(e); peerNode.Online += InvokeCommunicationStateChanged; peerNode.Offline += InvokeCommunicationStateChanged; }
/// <summary> /// Remove the peer node having the user communication address /// <c>address</c>. If no such node exists, nothing will happen. /// This method also fires the node lost event sigaling an explicit /// remove of the node. /// </summary> /// <param name="address">The socket address that the peer node reported /// as its user communication port.</param> void removePeerNode(SocketAddress address) { NodeLostHandler evt = this.NodeLost; lock (this.peerNodes) { PeerNode peerNode = this.peerNodes.Find(delegate(PeerNode p) { return(p.Address.Equals(address)); }); if (peerNode != null) { this.peerNodes.Remove(peerNode); /* Fire the event. */ if (evt != null) { evt(this, peerNode, NodeLostReason.LOST_EXPLICITLY); } } } }
void init() { try { Logger.LogFuncUp(); #region Fields initialization _printerAE = ""; _ourAE = ""; _printerIP = ""; _printerPort = 0; _printPriority = PRINT_PRIORITY.MEDIUM; _copies = 1; _layout = ""; _sheetImageCount = 1; #endregion #region Fields setting by parsing configure file _ourAE = _printer.OurAE; _printerAE = _printer.DefaultAE; Orientation = (Orientation)_printer.DefaultOrientation; PeerNode peerNode = new PeerNode(); if (-1 == _printer.GetPacsNodeParametersByAE(_printerAE, ref peerNode)) { Logger.LogError("Not found default Pacs Node for filming"); } _printerPort = peerNode.PeerPort; _printerIP = peerNode.PeerIP; #endregion Logger.LogFuncDown(); } catch (Exception ex) { Logger.LogFuncException(ex.Message + ex.StackTrace); throw; } }