/// <summary> /// Initializes the services of MS-WEBSS with the specified transport type, soap version and user authentication provided by the test case. /// </summary> /// <param name="transportType">The type of the connection</param> /// <param name="soapVersion">The soap version of the protocol message</param> /// <param name="userAuthentication">a user authenticated</param> /// <param name="serverRelativeUrl"> a Server related URL</param> public void InitializeService(TransportProtocol transportType, SoapProtocolVersion soapVersion, UserAuthentication userAuthentication, string serverRelativeUrl) { this.service = Proxy.CreateProxy<WebsSoap>(this.Site); this.service.SoapVersion = soapVersion; // select transport protocol switch (transportType) { case TransportProtocol.HTTP: this.service.Url = serverRelativeUrl; break; default: this.service.Url = serverRelativeUrl; // when request URL include HTTPS prefix, avoid closing base connection. // local client will accept all certificate after execute this function. Common.AcceptServerCertificate(); break; } this.service.Credentials = AdapterHelper.ConfigureCredential(userAuthentication); // Configure the service timeout. int soapTimeOut = Common.GetConfigurationPropertyValue<int>("ServiceTimeOut", this.Site); // 60000 means the configure SOAP Timeout is in minute. this.service.Timeout = soapTimeOut * 60000; }
// Konstruktor public STUNClient(String HostnameOrIP, int Port, TransportProtocol TransportProtocol, IPVersion IPVersion) { m_Port = Port; m_TransportProtocol = TransportProtocol; IPAddress dummy; if (IPAddress.TryParse(HostnameOrIP, out dummy)) m_IP = HostnameOrIP; else { try { IPHostEntry hostInfo = Dns.GetHostEntry(HostnameOrIP); // IPv4 if (IPVersion == STUNClient.IPVersion.IPv4) { // alle Einträge nach IPv4 Adresse durchsuchen foreach (IPAddress ip in hostInfo.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { m_IP = ip.ToString(); break; } } // falls keine IPv4 Adresse gefunden wurde if (m_IP == null) throw new Exception("Zu dem angegebenen Host konnte keine IPv4 Adresse gefunden werden"); } // andernfalls IPv6 else { // alle Einträge nach IPv6 Adresse durchsuchen foreach (IPAddress ip in hostInfo.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { m_IP = ip.ToString(); break; } } // falls keine IPv6 Adresse gefunden wurde if (m_IP == null) throw new Exception("Zu dem angegebenen Host konnte keine IPv6 Adresse gefunden werden"); } } catch (Exception e) { throw e; } } }
public PacketLogEntry(DateTime time, TransportProtocol protocol, DirectionType direction, DhtAddress address, byte[] data) { Time = time; Protocol = protocol; Direction = direction; Address = address; Data = data; }
public Flow[] GetFlowsBySrcPortAndTransport(ushort port, TransportProtocol proto, DateTime start, DateTime end) { return((from f in _Flows where f.StartTime.CompareTo(start) >= 0 && f.StartTime.CompareTo(end) <= 0 && f.PortA == port && f.TransportProto == proto orderby f.StartTime select f).ToArray()); }
//TODO remove protected attribute - temporary usage only, till GetURI will work fully OK protected void AdjustVideo( TransportProtocol protocol, StreamType streamType, MediaUri streamUri, VideoEncoderConfiguration conf) { VideoUtils.AdjustVideo(_videoForm, _username, _password, _messageTimeout, protocol, streamType, streamUri, conf); }
public PortMapping(TransportProtocol protocol, IPAddress publicIpAddress, ushort publicPort, IPAddress privateIpAddress, ushort privatePort) { Protocol = protocol; PublicIpAddress = publicIpAddress; PublicPort = publicPort; PrivateIpAddress = privateIpAddress; PrivatePort = privatePort; }
/// <summary> /// Get Stream URI for camera by using the Camera stream number (from the XML file) /// as an index to an Onvif media profile as returned by the Onvif GetProfiles() command /// </summary> /// <returns></returns> public Uri GetCameraUri(TransportProtocol tProtocol, StreamType sType) { if (!OnvifData.IsOnvifLoaded) { OnvifData.LoadOnvifData(this, 80, sType, tProtocol, StreamIndex); } return(OnvifData.StreamUri); // StreamUris[StreamIndex - 1]; }
public void SendEchoMessageWithCount(TransportProtocol protocol, int count) { sending_count_ = count; for (int i = 0; i < count; ++i) { sendEchoMessage(protocol); } }
MediaUri GetVideoMediaUri(TestVideoEncoderConfigurationOptions test, CopyVideoEncoderConfiguration copyMethod, string profileRequirementsDescription, VideoEncoding encoding, TransportProtocol protocol, StreamType streamType) { return(GetVideoMediaUri(test, copyMethod, profileRequirementsDescription, encoding, protocol, streamType, null)); }
public Flow(IPAddress ip1, ushort port1, IPAddress ip2, ushort port2, TransportProtocol proto) { _PacketsAB = 1; _IpA = ip1; _IpB = ip2; _PortA = port1; _PortB = port2; _TransportProto = proto; }
protected void SimplePlaybackTest(bool reverse, TransportProtocol protocol) { _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { if (_rtpPackets.Count > 1) { RtpPacket prev = _rtpPackets[_rtpPackets.Count - 2]; RtpPacket curr = _rtpPackets[_rtpPackets.Count - 1]; if (!reverse && prev.IsNextInTime(prev)) { throw new VideoException("Error: wrong NTP timestamps order in packets"); } if (reverse && curr.IFrameStart && _lastIFrame != null && _lastIFrame != curr && !curr.IsNextInRTPTime(_lastIFrame)) { throw new VideoException("Error: wrong RTP timestamps order in iframe packets"); } if (reverse && curr.OrdinaryFrameStart && !prev.IsNextInRTPTime(curr)) { throw new VideoException("Error: wrong RTP timestamps order in GOP packets"); } } return(true); } return(false); }; RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, protocol); _videoForm.ReplayReverse = reverse; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(reverse ? recInfo.LatestRecording : recInfo.EarliestRecording), reverse ? "Scale: -1.0" : string.Empty }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }); }, () => { _videoForm.ReplayReverse = false; Cleanup(); }); }
protected MediaUri GetJpegMediaUri(StreamType streamType, TransportProtocol protocol) { return(GetVideoMediaUri( (options) => { return (options.JPEG != null); }, (profile, options) => { AdjustJPEGVideoEncoderConfiguration(profile, options); }, "JPEG", VideoEncoding.JPEG, protocol, streamType)); }
protected MediaUri GetG711MediaUri(StreamType streamType, TransportProtocol protocol) { return(GetAudioMediaUri( options => (CheckAudioSupport(options, AudioEncoding.G711)), "G.711", AudioEncoding.G711, streamType, protocol, null)); }
public FunapiMulticast(FunapiSession session, FunEncoding encoding, TransportProtocol protocol = TransportProtocol.kDefault) { FunDebug.Assert(session != null); session_ = session; encoding_ = encoding; protocol_ = protocol; session_.MulticastMessageCallback += onReceivedMessage; }
private void OnTransportConnectFailed(TransportProtocol protocol) { DebugUtils.Log("OnTransportConnectFailed called."); // If you want to try to reconnect, call 'Connect' or 'Reconnect' function. // Be careful to avoid falling into an infinite loop. //network_.Connect(protocol, new HostHttp("127.0.0.1", 8018)); //network_.Reconnect(protocol); }
private SecureSocketServer(TransportProtocol protocol, Packager packager) { Protocol = protocol; _packager = packager; _callbacks = new CallbackManager <SecureSocketConnectedClient>(); Clients = new ClientManager(); _remoteFuncs = new RemoteCallServerManager(_packager); SetHandler <RemoteCallRequest>((cl, att) => _remoteFuncs.HandleClientFunctionCall(cl, att)); }
/// <summary> /// Gets the transport protocol being used by the channel. /// </summary> public TransportProtocol GetTransportProtocol() { TransportProtocol ret = (TransportProtocol)RCFProtoPINVOKE.RcfProtoChannel_getTransportProtocol(swigCPtr); if (RCFProtoPINVOKE.SWIGPendingException.Pending) { throw RCFProtoPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
protected MediaUri GetG726MediaUri(StreamType streamType, TransportProtocol protocol, MediaConfigurationChangeLog changeLog) { return(GetAudioMediaUri( options => (CheckAudioSupport(options, AudioEncoding.G726)), "G.726", AudioEncoding.G726, streamType, protocol, null, changeLog)); }
protected MediaUri GetAACMediaUri(StreamType streamType, TransportProtocol protocol) { return(GetAudioMediaUri( options => (CheckAudioSupport(options, AudioEncoding.AAC)), "AAC", AudioEncoding.AAC, streamType, protocol, null)); }
/// <summary> /// This operation is used to switch to the corresponding WebApplication according to AuthenticationMode. /// </summary> /// <param name="authenticationMode">The current Authentication Mode.</param> public void SwitchWebApplication(AuthenticationMode authenticationMode) { TransportProtocol currenTransportType = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site); if (currenTransportType == TransportProtocol.HTTP) { switch (authenticationMode) { case AuthenticationMode.Forms: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("FormsAuthenticationUrlForHTTP", this.Site); break; case AuthenticationMode.None: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("NoneAuthenticationUrlForHTTP", this.Site); break; case AuthenticationMode.Passport: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("PassportAuthenticationUrlForHTTP", this.Site); break; case AuthenticationMode.Windows: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("WindowsAuthenticationUrlForHTTP", this.Site); break; } } else if (currenTransportType == TransportProtocol.HTTPS) { // When request Url include HTTPS prefix, avoid closing base connection. // Local client will accept all certificates after executing this function. Common.AcceptServerCertificate(); switch (authenticationMode) { case AuthenticationMode.Forms: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("FormsAuthenticationUrlForHTTPS", this.Site); break; case AuthenticationMode.None: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("NoneAuthenticationUrlForHTTPS", this.Site); break; case AuthenticationMode.Passport: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("PassportAuthenticationUrlForHTTPS", this.Site); break; case AuthenticationMode.Windows: this.authwsServiceStub.Url = Common.GetConfigurationPropertyValue("WindowsAuthenticationUrlForHTTPS", this.Site); break; } } else { Site.Assume.Fail("The property 'TransportType' value at the ptfconfig file must be HTTP or HTTPS."); } }
/// <summary> /// Overrides IAdapter's Initialize(). /// </summary> /// <param name="testSite">A parameter represents an ITestSite instance.</param> public override void Initialize(ITestSite testSite) { base.Initialize(testSite); testSite.DefaultProtocolDocShortName = "MS-ADMINS"; // Initialize the AdminSoap. this.adminService = Proxy.CreateProxy <AdminSoap>(this.Site); // Merge the common configuration into local configuration string conmmonConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", this.Site); // Execute the merge the common configuration Common.MergeGlobalConfig(conmmonConfigFileName, this.Site); Common.CheckCommonProperties(this.Site, true); // Load SHOULDMAY configuration Common.MergeSHOULDMAYConfig(this.Site); TransportProtocol transport = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site); switch (transport) { case TransportProtocol.HTTP: { this.adminService.Url = Common.GetConfigurationPropertyValue("HTTPTargetServiceUrl", this.Site); break; } default: { this.adminService.Url = Common.GetConfigurationPropertyValue("HTTPSTargetServiceUrl", this.Site); // When request Url include HTTPS prefix, avoid closing base connection. // Local client will accept all certificates after executing this function. Common.AcceptServerCertificate(); break; } } string userName = Common.GetConfigurationPropertyValue("UserName", this.Site); string password = Common.GetConfigurationPropertyValue("Password", this.Site); string domain = Common.GetConfigurationPropertyValue("Domain", this.Site); this.adminService.Credentials = new NetworkCredential(userName, password, domain); this.SetSoapVersion(this.adminService); // Configure the service timeout. string soapTimeOut = Common.GetConfigurationPropertyValue("ServiceTimeOut", this.Site); // 60000 means the configure SOAP Timeout is in milliseconds. this.adminService.Timeout = Convert.ToInt32(soapTimeOut) * 60000; }
public SyncIOServer(TransportProtocol protocol, Packager packager) { Clients = new ClientManager(); Protocol = protocol; _packager = packager; _callbacks = new CallbackManager <SyncIOConnectedClient>(); _remoteFuncs = new RemoteCallServerManager(_packager); SetHandler <RemoteCallRequest>(_remoteFuncs.HandleClientFunctionCall); }
protected MediaUri GetJpegMediaUri(StreamType streamType, TransportProtocol protocol, IPType addressType) { return(GetVideoMediaUri( (options) => { return (options.JPEG != null); }, (profile, options) => { }, "JPEG", VideoEncoding.JPEG, protocol, streamType, addressType)); }
protected MediaUri GetJpegG711MediaUri(StreamType streamType, TransportProtocol protocol) { return(GetAudioVideoMediaUri((options) => { return (options.JPEG != null); }, "JPEG", VideoEncoding.JPEG, options => (CheckAudioSupport(options, AudioEncoding.G711)), "G.711", AudioEncoding.G711, streamType, protocol)); }
protected MediaUri GetJpegAacMediaUri(StreamType streamType, TransportProtocol protocol) { return(GetAudioVideoMediaUri(options => (options.JPEG != null), "JPEG", VideoEncoding.JPEG, options => (CheckAudioSupport(options, AudioEncoding.AAC)), "AAC", AudioEncoding.AAC, streamType, protocol)); }
protected MediaUri GetJpegG726MediaUri(StreamType streamType, TransportProtocol protocol, MediaConfigurationChangeLog changeLog) { return(GetAudioVideoMediaUri(options => (options.JPEG != null), "JPEG", VideoEncoding.JPEG, options => (CheckAudioSupport(options, AudioEncoding.G726)), "G.726", AudioEncoding.G726, streamType, protocol, changeLog)); }
MediaUri GetAudioVideoMediaUri(TestVideoEncoderConfigurationOptions videoTest, string videoCodec, VideoEncoding encoding, TestAudioEncoderConfigurationOptions audioTest, string audioCodec, AudioEncoding audioEncoding, StreamType streamType, TransportProtocol protocol) { return(GetAudioVideoMediaUri( videoTest, videoCodec, encoding, audioTest, audioCodec, audioEncoding, streamType, protocol, null)); }
void SetConnectionString(TransportProtocol transportProtocol) { if (m_connectionType == ConnectionType.DataChannel || m_connectionType == ConnectionType.CommandChannel) // don't need transport protocol if it is a data channel or command channel. { if (keyvaluepairs.ContainsKey("transportprotocol")) { keyvaluepairs.Remove("transportprotocol"); } if (keyvaluepairs.ContainsKey("protocol")) { keyvaluepairs.Remove("protocol"); } } else { if (!keyvaluepairs.ContainsKey("transportprotocol") && !keyvaluepairs.ContainsKey("protocol")) { keyvaluepairs.Add("transportprotocol", transportProtocol.ToString()); } else if (keyvaluepairs.ContainsKey("transportprotocol")) { keyvaluepairs["transportprotocol"] = transportProtocol.ToString(); } else if (keyvaluepairs.ContainsKey("protocol")) { keyvaluepairs["protocol"] = transportProtocol.ToString(); } } if ((bool)CheckboxForceIPv4.IsChecked) { if (!keyvaluepairs.ContainsKey("interface")) { keyvaluepairs.Add("interface", "0.0.0.0"); } else { keyvaluepairs["interface"] = "0.0.0.0"; } } else { keyvaluepairs.Remove("interface"); } m_connectionString = string.Empty; foreach (KeyValuePair <string, string> keyvalue in keyvaluepairs) { m_connectionString += keyvalue.Key + "=" + keyvalue.Value + "; "; } }
protected MediaUri GetJpegG726MediaUri(StreamType streamType, TransportProtocol protocol, IPType addressType) { return(GetAudioVideoMediaUri( (options) => { return (options.JPEG != null); }, "JPEG", VideoEncoding.JPEG, options => (CheckAudioSupport(options, AudioEncoding.G726)), "G726", AudioEncoding.G726, streamType, protocol, addressType)); }
protected MediaUri GetH264MediaUri(StreamType streamType, TransportProtocol protocol) { return(GetVideoMediaUri( (options) => { return (options.H264 != null); }, (profile, options) => { AdjustH264VideoEncoderConfiguration(profile, options); }, "H.264", VideoEncoding.H264, protocol, streamType)); }
private string FromTransportProtocol(TransportProtocol proto) { switch (proto) { case TransportProtocol.UDP: return("udp"); case TransportProtocol.RTP_AVP: return("RTP/AVP"); case TransportProtocol.RTP_SAVP: return("RTP/SAVP"); default: return("unknown"); } }
public Builder Clear() { _port = 0; _connection = null; _type = RTSP.SDP.MediaType.UNKNOWN; _proto = TransportProtocol.UNKNOWN; _fmts.Clear(); _attributes.Clear(); _bandwidths.Clear(); return(this); }
/// <summary> /// Connects to a remote server. /// </summary> /// <param name="ip">The IP address of the server.</param> /// <param name="port">The port of the server.</param> /// <param name="protocol">The protocol to connect using.</param> public void Connect(string ip, int port, TransportProtocol protocol, IPVersion ipVersion) { Client.Connect(ip, port, protocol, ipVersion); if (Connected) { Debug.Log("Connected to " + ip + " on port " + port + " using " + protocol + " and " + ipVersion + "."); } else { Debug.Log("Connection failed to " + ip + " on port " + port + " using " + protocol + " and " + ipVersion + "."); } }
/// <summary> /// The Overridden Initialize method, it includes the initialization logic of this adapter. /// </summary> /// <param name="testSite">The ITestSite member of ManagedAdapterBase</param> public override void Initialize(ITestSite testSite) { base.Initialize(testSite); this.defaultUserName = Common.GetConfigurationPropertyValue("UserName", this.Site); this.defaultPassword = Common.GetConfigurationPropertyValue("Password", this.Site); this.defaultDomain = Common.GetConfigurationPropertyValue("Domain", this.Site); this.currentTransport = Common.GetConfigurationPropertyValue<TransportProtocol>("TransportType", this.Site); if (TransportProtocol.HTTPS == this.currentTransport) { Common.AcceptServerCertificate(); } }
/// <summary> /// The Overridden Initialize method, it includes the initialization logic of this adapter. /// </summary> /// <param name="testSite">The ITestSite member of ManagedAdapterBase</param> public override void Initialize(ITestSite testSite) { base.Initialize(testSite); TransportProtocol transport = Common.GetConfigurationPropertyValue<TransportProtocol>("TransportType", this.Site); if (TransportProtocol.HTTPS == transport) { Common.AcceptServerCertificate(); } // In this moment, the thread user should not be impersonated. if (null != WindowsIdentity.GetCurrent(true)) { string errorMsg = string.Format("Current thread[{0}]: The thread user should not be impersonated in adapter initialization.", Thread.CurrentThread.ManagedThreadId); throw new InvalidOperationException(errorMsg); } this.PatternOfRequestWOPIViewFile = Common.GetConfigurationPropertyValue("RequestWOPIViewFileUrlPattern", this.Site); this.PatternOfRequestWOPIViewFolder = Common.GetConfigurationPropertyValue("RequestWOPIViewFolderUrlPattern", this.Site); this.currentTransport = Common.GetConfigurationPropertyValue<TransportProtocol>("TransportType", this.Site); }
public void SendMessage(MessageType msg_type, object message, EncryptionType encryption = EncryptionType.kDefaultEncryption, TransportProtocol protocol = TransportProtocol.kDefault, string expected_reply_type = null, float expected_reply_time = 0f, TimeoutEventHandler onReplyMissed = null) { string _msg_type = MessageTable.Lookup(msg_type); SendMessage(_msg_type, message, encryption, protocol, expected_reply_type, expected_reply_time, onReplyMissed); }
public void SendMessage(string msg_type, object message, EncryptionType encryption = EncryptionType.kDefaultEncryption, TransportProtocol protocol = TransportProtocol.kDefault, string expected_reply_type = null, float expected_reply_time = 0f, TimeoutEventHandler onReplyMissed = null) { if (protocol == TransportProtocol.kDefault) protocol = GetMessageProtocol(msg_type); bool transport_reliability = (protocol == TransportProtocol.kTcp && session_reliability_); // Invalidates session id if it is too stale. if (last_received_.AddSeconds(kFunapiSessionTimeout) < DateTime.Now) { DebugUtils.Log("Session is too stale. The server might have invalidated my session. Resetting."); session_id_ = ""; } FunapiTransport transport = GetTransport(protocol); if (transport != null && transport.state == FunapiTransport.State.kEstablished && (transport_reliability == false || unsent_queue_.Count <= 0)) { FunapiMessage fun_msg = null; if (transport.Encoding == FunEncoding.kJson) { fun_msg = new FunapiMessage(protocol, msg_type, transport.JsonHelper.Clone(message), encryption); // Encodes a messsage type transport.JsonHelper.SetStringField(fun_msg.message, kMsgTypeBodyField, msg_type); // Encodes a session id, if any. if (session_id_.Length > 0) { transport.JsonHelper.SetStringField(fun_msg.message, kSessionIdBodyField, session_id_); } if (transport_reliability) { transport.JsonHelper.SetIntegerField(fun_msg.message, kSeqNumberField, seq_); ++seq_; send_queue_.Enqueue(fun_msg); DebugUtils.DebugLog("{0} send message - msgtype:{1} seq:{2}", protocol, msg_type, seq_ - 1); } else { DebugUtils.DebugLog("{0} send message - msgtype:{1}", protocol, msg_type); } } else if (transport.Encoding == FunEncoding.kProtobuf) { fun_msg = new FunapiMessage(protocol, msg_type, message, encryption); FunMessage pbuf = fun_msg.message as FunMessage; pbuf.msgtype = msg_type; // Encodes a session id, if any. if (session_id_.Length > 0) { pbuf.sid = session_id_; } if (transport_reliability) { pbuf.seq = seq_; ++seq_; send_queue_.Enqueue(fun_msg); DebugUtils.DebugLog("{0} send message - msgtype:{1} seq:{2}", protocol, msg_type, pbuf.seq); } else { DebugUtils.DebugLog("{0} send message - msgtype:{1}", protocol, msg_type); } } if (expected_reply_type != null && expected_reply_type.Length > 0) { AddExpectedReply(fun_msg, expected_reply_type, expected_reply_time, onReplyMissed); } transport.SendMessage(fun_msg); } else if (transport != null && (transport_reliability || transport.state == FunapiTransport.State.kEstablished)) { if (transport.Encoding == FunEncoding.kJson) { if (transport == null) unsent_queue_.Enqueue(new FunapiMessage(protocol, msg_type, message, encryption)); else unsent_queue_.Enqueue(new FunapiMessage(protocol, msg_type, transport.JsonHelper.Clone(message), encryption)); } else if (transport.Encoding == FunEncoding.kProtobuf) { unsent_queue_.Enqueue(new FunapiMessage(protocol, msg_type, message, encryption)); } DebugUtils.Log("SendMessage - '{0}' message queued.", msg_type); } else { StringBuilder strlog = new StringBuilder(); strlog.AppendFormat("SendMessage - '{0}' message skipped.", msg_type); if (transport == null) strlog.AppendFormat(" There's no '{0}' transport.", protocol); else if (transport.state != FunapiTransport.State.kEstablished) strlog.AppendFormat(" Transport's state is '{0}'.", transport.state); DebugUtils.Log(strlog.ToString()); } }
public bool Redirect(TransportProtocol protocol, HostAddr addr, bool keep_session_id = false) { FunapiTransport transport = GetTransport(protocol); if (transport == null) { DebugUtils.LogWarning("Redirect - Can't find a {0} transport.", protocol); return false; } if (!keep_session_id) { InitSession(); } transport.Redirect(addr); return true; }
public void RegisterHandlerWithProtocol(string type, TransportProtocol protocol, MessageEventHandler handler) { if (protocol == TransportProtocol.kDefault) { RegisterHandler(type, handler); return; } DebugUtils.DebugLog("New handler for and message type '{0}' of '{1}' protocol.", type, protocol); message_protocols_[type] = protocol; message_handlers_[type] = handler; }
private void OnTransportFailure(TransportProtocol protocol) { DebugUtils.Log("OnTransportFailure({0}) - {1}", protocol, network_.LastErrorCode(protocol)); }
//--------------------------------------------------------------------- // Protocol-related functions //--------------------------------------------------------------------- public void SetDefaultProtocol(TransportProtocol protocol) { DebugUtils.Assert(protocol != TransportProtocol.kDefault); default_protocol_ = protocol; DebugUtils.Log("SetProtocol - default protocol is '{0}'.", protocol); }
private void OnConnectTimeout(TransportProtocol protocol) { DebugUtils.Log("{0} Transport Connection timed out.", protocol); }
private void Connect(TransportProtocol protocol) { DebugUtils.Log("-------- Connect --------\n{0}", DateTime.Now); if (network_ == null || !network_.SessionReliability) { network_ = new FunapiNetwork(with_session_reliability_); network_.ResponseTimeout = 10f; network_.OnSessionInitiated += new FunapiNetwork.SessionInitHandler(OnSessionInitiated); network_.OnSessionClosed += new FunapiNetwork.SessionCloseHandler(OnSessionClosed); network_.MaintenanceCallback += new FunapiNetwork.MessageEventHandler(OnMaintenanceMessage); network_.StoppedAllTransportCallback += new FunapiNetwork.NotifyHandler(OnStoppedAllTransport); network_.TransportConnectFailedCallback += new TransportEventHandler(OnTransportConnectFailed); network_.TransportDisconnectedCallback += new TransportEventHandler(OnTransportDisconnected); network_.RegisterHandler("echo", this.OnEcho); network_.RegisterHandler("pbuf_echo", this.OnEchoWithProtobuf); //network_.SetMessageProtocol(TransportProtocol.kTcp, "echo"); //network_.SetMessageProtocol(TransportProtocol.kUdp, "pbuf_echo"); FunapiTransport transport = GetNewTransport(protocol); network_.AttachTransport(transport); } else { if (!network_.HasTransport(protocol)) { FunapiTransport transport = GetNewTransport(protocol); network_.AttachTransport(transport); } network_.SetDefaultProtocol(protocol); } network_.Start(); }
private FunapiTransport FindOtherTransport(TransportProtocol protocol) { lock (transports_lock_) { if (protocol == TransportProtocol.kDefault || transports_.Count <= 0) return null; foreach (FunapiTransport transport in transports_.Values) { if (transport.Protocol != protocol && transport.Started) { return transport; } } } return null; }
public void StopTransport(TransportProtocol protocol) { StopTransport(GetTransport(protocol)); }
// Set message protocol public void SetMessageProtocol(TransportProtocol protocol, string msg_type) { DebugUtils.Assert(protocol != TransportProtocol.kDefault); message_protocols_[msg_type] = protocol; }
public void DetachTransport(TransportProtocol protocol) { lock (transports_lock_) { if (transports_.ContainsKey(protocol)) { FunapiTransport transport = transports_[protocol]; if (transport != null && transport.Started) StopTransport(transport); transports_.Remove(protocol); DebugUtils.Log("{0} transport detached.", protocol); if (protocol == default_protocol_) { FunapiTransport other = FindOtherTransport(transport.Protocol); if (other != null) { SetDefaultProtocol(other.Protocol); } else { default_protocol_ = TransportProtocol.kDefault; DebugUtils.LogWarning("DetachTransport - Deletes default protocol. You need to set default protocol up."); } } } else { DebugUtils.LogWarning("DetachTransport - Can't find a transport of '{0}' type.", protocol); } } }
private void CheckTransportConnection(TransportProtocol protocol) { lock (state_lock_) { if (state_ == State.kStopped) return; if (state_ == State.kWaitForSession && protocol == session_protocol_) { FunapiTransport other = FindOtherTransport(protocol); if (other != null) { other.state = FunapiTransport.State.kWaitForSession; SendEmptyMessage(other.Protocol); } else { state_ = State.kStarted; } } lock (transports_lock_) { bool all_stopped = true; foreach (FunapiTransport t in transports_.Values) { if (t.IsConnecting || t.Started) { all_stopped = false; break; } } if (all_stopped) { state_ = State.kStopped; OnStoppedAllTransportCallback(); } } } }
public FunEncoding GetEncoding(TransportProtocol protocol) { FunapiTransport transport = GetTransport(protocol); if (transport == null) return FunEncoding.kNone; return transport.Encoding; }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { base.BeginProcessing(); // Verify parameter set bool haveProtocolParam = this.MyInvocation.BoundParameters.ContainsKey("Protocol"); bool haveWsmanAuthenticationParam = this.MyInvocation.BoundParameters.ContainsKey("WsmanAuthentication"); bool haveDcomAuthenticationParam = this.MyInvocation.BoundParameters.ContainsKey("DcomAuthentication"); bool haveDcomImpersonation = this.MyInvocation.BoundParameters.ContainsKey("Impersonation"); _transportProtocol = (this.Protocol.Equals(ComputerWMIHelper.WsmanProtocol, StringComparison.OrdinalIgnoreCase) || (haveWsmanAuthenticationParam && !haveProtocolParam)) ? TransportProtocol.WSMan : TransportProtocol.DCOM; if (haveWsmanAuthenticationParam && (haveDcomAuthenticationParam || haveDcomImpersonation)) { string errMsg = StringUtil.Format(ComputerResources.StopCommandParamWSManAuthConflict, ComputerResources.StopCommandParamMessage); ThrowTerminatingError( new ErrorRecord( new PSArgumentException(errMsg), "InvalidParameter", ErrorCategory.InvalidArgument, this)); } if ((_transportProtocol == TransportProtocol.DCOM) && haveWsmanAuthenticationParam) { string errMsg = StringUtil.Format(ComputerResources.StopCommandWSManAuthProtcolConflict, ComputerResources.StopCommandParamMessage); ThrowTerminatingError( new ErrorRecord( new PSArgumentException(errMsg), "InvalidParameter", ErrorCategory.InvalidArgument, this)); } if ((_transportProtocol == TransportProtocol.WSMan) && (haveDcomAuthenticationParam || haveDcomImpersonation)) { string errMsg = StringUtil.Format(ComputerResources.StopCommandAuthProtcolConflict, ComputerResources.StopCommandParamMessage); ThrowTerminatingError( new ErrorRecord( new PSArgumentException(errMsg), "InvalidParameter", ErrorCategory.InvalidArgument, this)); } #if CORECLR if (this.MyInvocation.BoundParameters.ContainsKey("DcomAuthentication")) { string errMsg = StringUtil.Format(ComputerResources.InvalidParameterForCoreClr, "DcomAuthentication"); PSArgumentException ex = new PSArgumentException(errMsg, ComputerResources.InvalidParameterForCoreClr); ThrowTerminatingError(new ErrorRecord(ex, "InvalidParameterForCoreClr", ErrorCategory.InvalidArgument, null)); } if (this.MyInvocation.BoundParameters.ContainsKey("Impersonation")) { string errMsg = StringUtil.Format(ComputerResources.InvalidParameterForCoreClr, "Impersonation"); PSArgumentException ex = new PSArgumentException(errMsg, ComputerResources.InvalidParameterForCoreClr); ThrowTerminatingError(new ErrorRecord(ex, "InvalidParameterForCoreClr", ErrorCategory.InvalidArgument, null)); } if(this.Protocol.Equals(ComputerWMIHelper.DcomProtocol , StringComparison.OrdinalIgnoreCase)) { InvalidOperationException ex = new InvalidOperationException(ComputerResources.InvalidParameterDCOMNotSupported); ThrowTerminatingError(new ErrorRecord(ex, "InvalidParameterDCOMNotSupported", ErrorCategory.InvalidOperation, null)); } #endif }
public FunapiTransport GetTransport(TransportProtocol protocol) { lock (transports_lock_) { if (transports_.ContainsKey(protocol)) return transports_[protocol]; } return null; }
private FunapiTransport GetNewTransport(TransportProtocol protocol) { FunapiTransport transport = null; FunEncoding encoding = with_protobuf_ ? FunEncoding.kProtobuf : FunEncoding.kJson; if (FunapiConfig.IsValid) { transport = FunapiConfig.CreateTransport(protocol, encoding); } if (transport == null) { if (protocol == TransportProtocol.kTcp) { transport = new FunapiTcpTransport(kServerIp, (ushort)(with_protobuf_ ? 8022 : 8012), encoding); transport.AutoReconnect = true; //transport.EnablePing = true; //transport.DisableNagle = true; //((FunapiTcpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption); } else if (protocol == TransportProtocol.kUdp) { transport = new FunapiUdpTransport(kServerIp, (ushort)(with_protobuf_ ? 8023 : 8013), encoding); // Please set the same encryption type as the encryption type of server. //((FunapiUdpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption); } else if (protocol == TransportProtocol.kHttp) { transport = new FunapiHttpTransport(kServerIp, (ushort)(with_protobuf_ ? 8028 : 8018), false, encoding); // Send messages using WWW class //((FunapiHttpTransport)transport).UseWWW = true; // Please set the same encryption type as the encryption type of server. //((FunapiHttpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption); } } if (transport != null) { transport.StartedCallback += new TransportEventHandler(OnTransportStarted); transport.StoppedCallback += new TransportEventHandler(OnTransportClosed); transport.FailureCallback += new TransportEventHandler(OnTransportFailure); // Connect timeout. transport.ConnectTimeoutCallback += new TransportEventHandler(OnConnectTimeout); transport.ConnectTimeout = 10f; // If you prefer use specific Json implementation other than Dictionary, // you need to register json accessors to handle the Json implementation before FunapiNetwork::Start(). // E.g., transport.JsonHelper = new YourJsonAccessorClass // Adds extra server list // Use HostHttp for http transport. //transport.AddServerList(new List<HostAddr>{ // new HostAddr("127.0.0.1", 8012), new HostAddr("127.0.0.1", 8012), // new HostAddr("127.0.0.1", 8013), new HostAddr("127.0.0.1", 8018) //}); } return transport; }
public bool HasTransport(TransportProtocol protocol) { lock (transports_lock_) { if (transports_.ContainsKey(protocol)) return true; } return false; }
private void OnTransportClosed(TransportProtocol protocol) { DebugUtils.Log("{0} Transport closed.", protocol); }
//--------------------------------------------------------------------- //--------------------------------------------------------------------- public ErrorCode LastErrorCode(TransportProtocol protocol) { FunapiTransport transport = GetTransport(protocol); if (transport == null) return ErrorCode.kNone; return transport.LastErrorCode; }
private void OnTransportDisconnected(TransportProtocol protocol) { DebugUtils.Log("OnTransportDisconnected called."); }
public string LastErrorMessage(TransportProtocol protocol) { FunapiTransport transport = GetTransport(protocol); if (transport == null) return ""; return transport.LastErrorMessage; }
private void OnTransportStarted(TransportProtocol protocol) { DebugUtils.Log("{0} Transport started.", protocol); }
public bool Reconnect(TransportProtocol protocol) { FunapiTransport transport = GetTransport(protocol); if (transport == null) { DebugUtils.LogWarning("Reconnect - Can't find a {0} transport.", protocol); return false; } transport.Reconnect(); return true; }