mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:32:43 +00:00 
			
		
		
		
	IPv4: Rename source/destination in socket classes to local/peer.
It was way too ambiguous who's the source and who's the destination, and it didn't really follow a logical pattern. "Local port" vs "Peer port" is super obvious, so let's call it that.
This commit is contained in:
		
							parent
							
								
									780d2a08c4
								
							
						
					
					
						commit
						5e938868a2
					
				
					 7 changed files with 80 additions and 88 deletions
				
			
		|  | @ -36,7 +36,7 @@ TCPSocket::TCPSocket(int protocol) | |||
| TCPSocket::~TCPSocket() | ||||
| { | ||||
|     LOCKER(sockets_by_port().lock()); | ||||
|     sockets_by_port().resource().remove(source_port()); | ||||
|     sockets_by_port().resource().remove(local_port()); | ||||
| } | ||||
| 
 | ||||
| Retained<TCPSocket> TCPSocket::create(int protocol) | ||||
|  | @ -60,7 +60,7 @@ int TCPSocket::protocol_receive(const ByteBuffer& packet_buffer, void* buffer, s | |||
| 
 | ||||
| int TCPSocket::protocol_send(const void* data, int data_length) | ||||
| { | ||||
|     auto* adapter = adapter_for_route_to(destination_address()); | ||||
|     auto* adapter = adapter_for_route_to(peer_address()); | ||||
|     if (!adapter) | ||||
|         return -EHOSTUNREACH; | ||||
|     send_tcp_packet(TCPFlags::PUSH | TCPFlags::ACK, data, data_length); | ||||
|  | @ -70,14 +70,14 @@ int TCPSocket::protocol_send(const void* data, int data_length) | |||
| void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_size) | ||||
| { | ||||
|     // FIXME: Maybe the socket should be bound to an adapter instead of looking it up every time?
 | ||||
|     auto* adapter = adapter_for_route_to(destination_address()); | ||||
|     auto* adapter = adapter_for_route_to(peer_address()); | ||||
|     ASSERT(adapter); | ||||
| 
 | ||||
|     auto buffer = ByteBuffer::create_zeroed(sizeof(TCPPacket) + payload_size); | ||||
|     auto& tcp_packet = *(TCPPacket*)(buffer.pointer()); | ||||
|     ASSERT(source_port()); | ||||
|     tcp_packet.set_source_port(source_port()); | ||||
|     tcp_packet.set_destination_port(destination_port()); | ||||
|     ASSERT(local_port()); | ||||
|     tcp_packet.set_source_port(local_port()); | ||||
|     tcp_packet.set_destination_port(peer_port()); | ||||
|     tcp_packet.set_window_size(1024); | ||||
|     tcp_packet.set_sequence_number(m_sequence_number); | ||||
|     tcp_packet.set_data_offset(sizeof(TCPPacket) / sizeof(dword)); | ||||
|  | @ -93,18 +93,18 @@ void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_siz | |||
|     } | ||||
| 
 | ||||
|     memcpy(tcp_packet.payload(), payload, payload_size); | ||||
|     tcp_packet.set_checksum(compute_tcp_checksum(adapter->ipv4_address(), destination_address(), tcp_packet, payload_size)); | ||||
|     tcp_packet.set_checksum(compute_tcp_checksum(adapter->ipv4_address(), peer_address(), tcp_packet, payload_size)); | ||||
|     kprintf("sending tcp packet from %s:%u to %s:%u with (%s %s) seq_no=%u, ack_no=%u\n", | ||||
|         adapter->ipv4_address().to_string().characters(), | ||||
|         source_port(), | ||||
|         destination_address().to_string().characters(), | ||||
|         destination_port(), | ||||
|         local_port(), | ||||
|         peer_address().to_string().characters(), | ||||
|         peer_port(), | ||||
|         tcp_packet.has_syn() ? "SYN" : "", | ||||
|         tcp_packet.has_ack() ? "ACK" : "", | ||||
|         tcp_packet.sequence_number(), | ||||
|         tcp_packet.ack_number() | ||||
|     ); | ||||
|     adapter->send_ipv4(MACAddress(), destination_address(), IPv4Protocol::TCP, move(buffer)); | ||||
|     adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer)); | ||||
| } | ||||
| 
 | ||||
| NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket& packet, word payload_size) | ||||
|  | @ -150,11 +150,11 @@ NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source, | |||
| 
 | ||||
| KResult TCPSocket::protocol_connect(FileDescriptor& descriptor, ShouldBlock should_block) | ||||
| { | ||||
|     auto* adapter = adapter_for_route_to(destination_address()); | ||||
|     auto* adapter = adapter_for_route_to(peer_address()); | ||||
|     if (!adapter) | ||||
|         return KResult(-EHOSTUNREACH); | ||||
| 
 | ||||
|     allocate_source_port_if_needed(); | ||||
|     allocate_local_port_if_needed(); | ||||
| 
 | ||||
|     m_sequence_number = 0; | ||||
|     m_ack_number = 0; | ||||
|  | @ -171,7 +171,7 @@ KResult TCPSocket::protocol_connect(FileDescriptor& descriptor, ShouldBlock shou | |||
|     return KResult(-EINPROGRESS); | ||||
| } | ||||
| 
 | ||||
| int TCPSocket::protocol_allocate_source_port() | ||||
| int TCPSocket::protocol_allocate_local_port() | ||||
| { | ||||
|     static const word first_ephemeral_port = 32768; | ||||
|     static const word last_ephemeral_port = 60999; | ||||
|  | @ -182,7 +182,7 @@ int TCPSocket::protocol_allocate_source_port() | |||
|     for (word port = first_scan_port;;) { | ||||
|         auto it = sockets_by_port().resource().find(port); | ||||
|         if (it == sockets_by_port().resource().end()) { | ||||
|             set_source_port(port); | ||||
|             set_local_port(port); | ||||
|             sockets_by_port().resource().set(port, this); | ||||
|             return port; | ||||
|         } | ||||
|  | @ -203,8 +203,8 @@ bool TCPSocket::protocol_is_disconnected() const | |||
| KResult TCPSocket::protocol_bind() | ||||
| { | ||||
|     LOCKER(sockets_by_port().lock()); | ||||
|     if (sockets_by_port().resource().contains(source_port())) | ||||
|     if (sockets_by_port().resource().contains(local_port())) | ||||
|         return KResult(-EADDRINUSE); | ||||
|     sockets_by_port().resource().set(source_port(), this); | ||||
|     sockets_by_port().resource().set(local_port(), this); | ||||
|     return KSuccess; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling