Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _SendMessages(self, grr_msgs, background=False):
"""Sends a block of messages through Fleetspeak."""
message_list = rdf_flows.PackedMessageList()
communicator.Communicator.EncodeMessageList(
rdf_flows.MessageList(job=grr_msgs), message_list)
fs_msg = fs_common_pb2.Message(
message_type="MessageList",
destination=fs_common_pb2.Address(service_name="GRR"),
background=background)
fs_msg.data.Pack(message_list.AsPrimitiveProto())
for grr_msg in grr_msgs:
if (grr_msg.session_id is None or grr_msg.request_id is None or
grr_msg.response_id is None):
continue
# Place all ids in a single annotation, instead of having separate
# annotations for the flow-id, request-id and response-id. This reduces
# overall size of the annotations by half (~60 bytes to ~30 bytes).
annotation = fs_msg.annotations.entries.add()
annotation.key = _DATA_IDS_ANNOTATION_KEY
annotation.value = "%s:%d:%d" % (grr_msg.session_id.Basename(),
grr_msg.request_id, grr_msg.response_id)
if fs_msg.annotations.ByteSize() >= _MAX_ANNOTATIONS_BYTES:
break
def SendGrrMessageThroughFleetspeak(grr_id, grr_msg):
"""Sends the given GrrMessage through FS."""
fs_msg = fs_common_pb2.Message(
message_type="GrrMessage",
destination=fs_common_pb2.Address(
client_id=GRRIDToFleetspeakID(grr_id), service_name="GRR"))
fs_msg.data.Pack(grr_msg.AsPrimitiveProto())
if grr_msg.session_id is not None:
annotation = fs_msg.annotations.entries.add()
annotation.key, annotation.value = "flow_id", grr_msg.session_id.Basename()
if grr_msg.request_id is not None:
annotation = fs_msg.annotations.entries.add()
annotation.key, annotation.value = "request_id", str(grr_msg.request_id)
fleetspeak_connector.CONN.outgoing.InsertMessage(fs_msg)
def SendGrrMessageThroughFleetspeak(grr_id, grr_msg):
"""Sends the given GrrMessage through FS."""
fs_msg = fs_common_pb2.Message(
message_type="GrrMessage",
destination=fs_common_pb2.Address(
client_id=GRRIDToFleetspeakID(grr_id), service_name="GRR"))
fs_msg.data.Pack(grr_msg.AsPrimitiveProto())
if grr_msg.session_id is not None:
annotation = fs_msg.annotations.entries.add()
annotation.key, annotation.value = "flow_id", grr_msg.session_id.Basename()
if grr_msg.request_id is not None:
annotation = fs_msg.annotations.entries.add()
annotation.key, annotation.value = "request_id", str(grr_msg.request_id)
fleetspeak_connector.CONN.outgoing.InsertMessage(fs_msg)
def _SendMessages(self, grr_msgs, background=False):
"""Sends a block of messages through Fleetspeak."""
message_list = rdf_flows.PackedMessageList()
communicator.Communicator.EncodeMessageList(
rdf_flows.MessageList(job=grr_msgs), message_list)
fs_msg = fs_common_pb2.Message(
message_type="MessageList",
destination=fs_common_pb2.Address(service_name="GRR"),
background=background)
fs_msg.data.Pack(message_list.AsPrimitiveProto())
for grr_msg in grr_msgs:
if (grr_msg.session_id is None or grr_msg.request_id is None or
grr_msg.response_id is None):
continue
# Place all ids in a single annotation, instead of having separate
# annotations for the flow-id, request-id and response-id. This reduces
# overall size of the annotations by half (~60 bytes to ~30 bytes).
annotation = fs_msg.annotations.entries.add()
annotation.key = _DATA_IDS_ANNOTATION_KEY
annotation.value = "%s:%d:%d" % (grr_msg.session_id.Basename(),
grr_msg.request_id, grr_msg.response_id)