@@ -175,10 +175,13 @@ def send_message(self, message):
175175
176176 This method takes a P2P payload, builds the P2P header and adds
177177 the message to the send buffer to be sent over the socket."""
178+ tmsg = self .build_message (message )
179+ self ._log_message ("send" , message )
180+ return self .send_raw_message (tmsg )
181+
182+ def send_raw_message (self , raw_message_bytes ):
178183 if not self .is_connected :
179184 raise IOError ('Not connected' )
180- self ._log_message ("send" , message )
181- tmsg = self ._build_message (message )
182185
183186 def maybe_write ():
184187 if not self ._transport :
@@ -188,12 +191,12 @@ def maybe_write():
188191 # Python 3.4 versions.
189192 if hasattr (self ._transport , 'is_closing' ) and self ._transport .is_closing ():
190193 return
191- self ._transport .write (tmsg )
194+ self ._transport .write (raw_message_bytes )
192195 NetworkThread .network_event_loop .call_soon_threadsafe (maybe_write )
193196
194197 # Class utility methods
195198
196- def _build_message (self , message ):
199+ def build_message (self , message ):
197200 """Build a serialized P2P message"""
198201 command = message .command
199202 data = message .serialize ()
@@ -376,9 +379,9 @@ def wait_for_verack(self, timeout=60):
376379
377380 # Message sending helper functions
378381
379- def send_and_ping (self , message ):
382+ def send_and_ping (self , message , timeout = 60 ):
380383 self .send_message (message )
381- self .sync_with_ping ()
384+ self .sync_with_ping (timeout = timeout )
382385
383386 # Sync up with the node
384387 def sync_with_ping (self , timeout = 60 ):
0 commit comments