def send_content_info_request(self, content_type, request_list, limit=25, peer=None): """ Sends the generic content request of givent content_type. :param content_type: request content type :param request_list: List<string> request queries :param limit: Number of expected responses :param peer: Peer to send this request to """ cache = self.request_cache.add( ContentRequest(self.request_cache, content_type, request_list)) self.logger.info("Sending search request query:%s, identifier:%s", request_list, cache.number) content_request = ContentInfoRequest(cache.number, content_type, request_list, limit) packet = self.create_message_packet(MSG_CONTENT_INFO_REQUEST, content_request) if peer: self.broadcast_message(packet, peer=peer) else: for connected_peer in self.get_peers(): self.broadcast_message(packet, peer=connected_peer)
def subscribe(self, peer, subscribe=True): """ Method to send content subscribe/unsubscribe message. This message is sent to each individual publisher peer we want to subscribe/unsubscribe. """ cache = self.request_cache.add(ContentRequest(self.request_cache, MSG_SUBSCRIBE, None)) # Remove the publisher peer already if user is trying to unsubscribe if not subscribe: self.publishers.remove(peer) # Create subscription packet and send it subscription = ContentSubscription(cache.number, subscribe) packet = self.create_message_packet(MSG_SUBSCRIBE, subscription) self.broadcast_message(packet, peer=peer)