protected override void ProcessPacket(NewPacketEventArgs packetInfo) { DirectoryAgentAdvertPacket advert = packetInfo.Packet as DirectoryAgentAdvertPacket; if (advert != null) { ProcessDAAdvert(advert, packetInfo.SourceEndPoint); } ServiceRequestPacket request = packetInfo.Packet as ServiceRequestPacket; if (IsReplyRequired(request)) { SendServiceReply(packetInfo.SourceEndPoint, packetInfo.Packet.Header.XId); } ServiceAcknowledgePacket acknowledge = packetInfo.Packet as ServiceAcknowledgePacket; if (acknowledge != null) { RaiseServiceRegistered(); } AttributeRequestPacket attributeRequest = packetInfo.Packet as AttributeRequestPacket; if (IsReplyRequired(attributeRequest)) { SendAttributeReply(packetInfo.SourceEndPoint, packetInfo.Packet.Header.XId); } }
/// <summary> /// Sends an attribute request. /// This can either be to a specific URL or a general service URL. /// Results will be returned via the AttributeReply event /// </summary> /// <param name="scope">The scope.</param> /// <param name="url">The URL.</param> /// <returns> /// An id for this request which can be used to mtch it to the reply /// </returns> private int SendAttributeRequest(string scope, string url) { AttributeRequestPacket request = PrepareAttributeRequest(scope, url); socket.Send(request); return(request.Header.XId); }
/// <summary> /// Prepares the attribute request object. /// </summary> /// <param name="scope">The scope.</param> /// <param name="url">The URL.</param> /// <returns></returns> private AttributeRequestPacket PrepareAttributeRequest(string scope, string url) { AttributeRequestPacket request = new AttributeRequestPacket(); FillHeader(request.Header, NewTransactionId()); request.ScopeList = scope; request.Url = url; return(request); }
/// <summary> /// Determines whether a reply is required for the specified request. /// We should only respond to requests within the scope of the /// service /// </summary> /// <param name="request">The request.</param> /// <returns> /// <c>true</c> if reply is required; otherwise, <c>false</c>. /// </returns> private bool IsReplyRequired(AttributeRequestPacket request) { if (!IsReplyRequired((SlpRequestPacket)request)) { return(false); } //Does the requested url match this service? // The URL field can take two forms. // It can simply be a Service Type such as "http" or "service:tftp". // In this case, all attributes are returned if the type matches // Or it can be a full URl in which case we only reply if the full URL matches return(CheckUrlMatch(request.Url, ServiceAbstractType, ServiceConcreteType, ServiceAddress)); }