@@ -506,6 +506,9 @@ def _begin_new_stream(self, stream_id, allowed_ids):
506
506
:param stream_id: The ID of the stream to open.
507
507
:param allowed_ids: What kind of stream ID is allowed.
508
508
"""
509
+ self .config .logger .debug (
510
+ "Attempting to initiate stream ID %d" , stream_id
511
+ )
509
512
outbound = self ._stream_id_is_outbound (stream_id )
510
513
highest_stream_id = (
511
514
self .highest_outbound_stream_id if outbound else
@@ -526,10 +529,12 @@ def _begin_new_stream(self, stream_id, allowed_ids):
526
529
inbound_window_size = self .local_settings .initial_window_size ,
527
530
outbound_window_size = self .remote_settings .initial_window_size
528
531
)
532
+ self .config .logger .debug ("Stream ID %d created" , stream_id )
529
533
s .max_inbound_frame_size = self .max_inbound_frame_size
530
534
s .max_outbound_frame_size = self .max_outbound_frame_size
531
535
532
536
self .streams [stream_id ] = s
537
+ self .config .logger .debug ("Current streams: %s" , self .streams .keys ())
533
538
534
539
if outbound :
535
540
self .highest_outbound_stream_id = stream_id
@@ -543,6 +548,7 @@ def initiate_connection(self):
543
548
Provides any data that needs to be sent at the start of the connection.
544
549
Must be called for both clients and servers.
545
550
"""
551
+ self .config .logger .debug ("Initializing connection" )
546
552
self .state_machine .process_input (ConnectionInputs .SEND_SETTINGS )
547
553
if self .config .client_side :
548
554
preamble = b'PRI * HTTP/2.0\r \n \r \n SM\r \n \r \n '
@@ -552,6 +558,9 @@ def initiate_connection(self):
552
558
f = SettingsFrame (0 )
553
559
for setting , value in self .local_settings .items ():
554
560
f .settings [setting ] = value
561
+ self .config .logger .debug (
562
+ "Send Settings frame: %s" , self .local_settings
563
+ )
555
564
556
565
self ._data_to_send += preamble + f .serialize ()
557
566
@@ -588,8 +597,11 @@ def initiate_upgrade_connection(self, settings_header=None):
588
597
For servers, returns nothing.
589
598
:rtype: ``bytes`` or ``None``
590
599
"""
591
- frame_data = None
600
+ self .config .logger .debug (
601
+ "Upgrade connection. Current settings: %s" , self .local_settings
602
+ )
592
603
604
+ frame_data = None
593
605
# Begin by getting the preamble in place.
594
606
self .initiate_connection ()
595
607
@@ -617,6 +629,7 @@ def initiate_upgrade_connection(self, settings_header=None):
617
629
ConnectionInputs .SEND_HEADERS if self .config .client_side
618
630
else ConnectionInputs .RECV_HEADERS
619
631
)
632
+ self .config .logger .debug ("Process input %s" , connection_input )
620
633
self .state_machine .process_input (connection_input )
621
634
622
635
# Set up stream 1.
@@ -686,9 +699,12 @@ def get_next_available_stream_id(self):
686
699
# No streams have been opened yet, so return the lowest allowed stream
687
700
# ID.
688
701
if not self .highest_outbound_stream_id :
689
- return 1 if self .config .client_side else 2
690
-
691
- next_stream_id = self .highest_outbound_stream_id + 2
702
+ next_stream_id = 1 if self .config .client_side else 2
703
+ else :
704
+ next_stream_id = self .highest_outbound_stream_id + 2
705
+ self .config .logger .debug (
706
+ "Next available stream ID %d" , next_stream_id
707
+ )
692
708
if next_stream_id > self .HIGHEST_ALLOWED_STREAM_ID :
693
709
raise NoAvailableStreamIDError ("Exhausted allowed stream IDs" )
694
710
@@ -798,6 +814,10 @@ def send_headers(self, stream_id, headers, end_stream=False,
798
814
799
815
:returns: Nothing
800
816
"""
817
+ self .config .logger .debug (
818
+ "Send headers on stream ID %d" , stream_id
819
+ )
820
+
801
821
# Check we can open the stream.
802
822
if stream_id not in self .streams :
803
823
max_open_streams = self .remote_settings .max_concurrent_streams
@@ -871,6 +891,9 @@ def send_data(self, stream_id, data, end_stream=False, pad_length=None):
871
891
:type pad_length: ``int``
872
892
:returns: Nothing
873
893
"""
894
+ self .config .logger .debug (
895
+ "Send data on stream ID %d with len %d" , stream_id , len (data )
896
+ )
874
897
frame_size = len (data )
875
898
if pad_length is not None :
876
899
if not isinstance (pad_length , int ):
@@ -879,6 +902,9 @@ def send_data(self, stream_id, data, end_stream=False, pad_length=None):
879
902
raise ValueError ("pad_length must be within range: [0, 255]" )
880
903
# Account for padding bytes plus the 1-byte padding length field.
881
904
frame_size += pad_length + 1
905
+ self .config .logger .debug (
906
+ "Frame size on stream ID %d is %d" , stream_id , frame_size
907
+ )
882
908
883
909
if frame_size > self .local_flow_control_window (stream_id ):
884
910
raise FlowControlError (
@@ -899,6 +925,10 @@ def send_data(self, stream_id, data, end_stream=False, pad_length=None):
899
925
self ._prepare_for_sending (frames )
900
926
901
927
self .outbound_flow_control_window -= frame_size
928
+ self .config .logger .debug (
929
+ "Outbound flow control window size is %d" ,
930
+ self .outbound_flow_control_window
931
+ )
902
932
assert self .outbound_flow_control_window >= 0
903
933
904
934
def end_stream (self , stream_id ):
@@ -912,6 +942,7 @@ def end_stream(self, stream_id):
912
942
:type stream_id: ``int``
913
943
:returns: Nothing
914
944
"""
945
+ self .config .logger .debug ("End stream ID %d" , stream_id )
915
946
self .state_machine .process_input (ConnectionInputs .SEND_DATA )
916
947
frames = self .streams [stream_id ].end_stream ()
917
948
self ._prepare_for_sending (frames )
@@ -953,6 +984,10 @@ def increment_flow_control_window(self, increment, stream_id=None):
953
984
f .window_increment = increment
954
985
frames = [f ]
955
986
987
+ self .config .logger .debug (
988
+ "Increase stream ID %d flow control window by %d" ,
989
+ stream_id , increment
990
+ )
956
991
self ._prepare_for_sending (frames )
957
992
958
993
def push_stream (self , stream_id , promised_stream_id , request_headers ):
@@ -977,6 +1012,10 @@ def push_stream(self, stream_id, promised_stream_id, request_headers):
977
1012
:class:`HeaderTuple <hpack:hpack.HeaderTuple>` objects.
978
1013
:returns: Nothing
979
1014
"""
1015
+ self .config .logger .debug (
1016
+ "Send Push Promise frame on stream ID %d" , stream_id
1017
+ )
1018
+
980
1019
if not self .remote_settings .enable_push :
981
1020
raise ProtocolError ("Remote peer has disabled stream push" )
982
1021
@@ -1010,6 +1049,8 @@ def ping(self, opaque_data):
1010
1049
PING frame.
1011
1050
:returns: Nothing
1012
1051
"""
1052
+ self .config .logger .debug ("Send Ping frame" )
1053
+
1013
1054
if not isinstance (opaque_data , bytes ) or len (opaque_data ) != 8 :
1014
1055
raise ValueError ("Invalid value for ping data: %r" % opaque_data )
1015
1056
@@ -1035,6 +1076,7 @@ def reset_stream(self, stream_id, error_code=0):
1035
1076
:type error_code: ``int``
1036
1077
:returns: Nothing
1037
1078
"""
1079
+ self .config .logger .debug ("Reset stream ID %d" , stream_id )
1038
1080
self .state_machine .process_input (ConnectionInputs .SEND_RST_STREAM )
1039
1081
stream = self ._get_stream_by_id (stream_id )
1040
1082
frames = stream .reset_stream (error_code )
@@ -1057,6 +1099,7 @@ def close_connection(self, error_code=0, additional_data=None,
1057
1099
by the sender. Defaults to ``highest_inbound_stream_id``.
1058
1100
:returns: Nothing
1059
1101
"""
1102
+ self .config .logger .debug ("Close connection" )
1060
1103
self .state_machine .process_input (ConnectionInputs .SEND_GOAWAY )
1061
1104
1062
1105
# Additional_data must be bytes
@@ -1081,6 +1124,9 @@ def update_settings(self, new_settings):
1081
1124
1082
1125
:param new_settings: A dictionary of {setting: new value}
1083
1126
"""
1127
+ self .config .logger .debug (
1128
+ "Update connection settings to %s" , new_settings
1129
+ )
1084
1130
self .state_machine .process_input (ConnectionInputs .SEND_SETTINGS )
1085
1131
self .local_settings .update (new_settings )
1086
1132
s = SettingsFrame (0 )
@@ -1314,6 +1360,10 @@ def acknowledge_received_data(self, acknowledged_size, stream_id):
1314
1360
:returns: Nothing
1315
1361
:rtype: ``None``
1316
1362
"""
1363
+ self .config .logger .debug (
1364
+ "Ack received data on stream ID %d with size %d" ,
1365
+ stream_id , acknowledged_size
1366
+ )
1317
1367
if stream_id <= 0 :
1318
1368
raise ValueError (
1319
1369
"Stream ID %d is not valid for acknowledge_received_data" %
@@ -1459,6 +1509,10 @@ def receive_data(self, data):
1459
1509
:returns: A list of events that the remote peer triggered by sending
1460
1510
this data.
1461
1511
"""
1512
+ self .config .logger .debug (
1513
+ "Process received data on connection. Received data: %r" , data
1514
+ )
1515
+
1462
1516
events = []
1463
1517
self .incoming_buffer .add_data (data )
1464
1518
self .incoming_buffer .max_frame_size = self .max_inbound_frame_size
0 commit comments