Skip to content

Commit

Permalink
Update Examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
636f7374 committed May 28, 2024
1 parent 16b24fe commit 2482a20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ begin
{"twitter.com", "example.com", "google.com"}.each_with_index do |domain, index|
# Create DNS Packet Query (AssociateUDP).

dns_ask = DNS::Packet.create_getaddrinfo_ask protocol_type: DNS::ProtocolType::UDP, name: domain, record_type: DNS::Packet::RecordFlag::A
dns_ask = DNS::Packet.create_query_packet protocol_type: DNS::ProtocolType::UDP, name: domain, record_type: DNS::Packet::RecordFlag::A
dns_ask.transmissionId = Random.new.rand type: UInt16

# Send DNS Packet Query (AssociateUDP) & Receive 4096 Bytes, because Fragment and DNS query may be larger than 512 Bytes. (AssociateUDP).
Expand Down
15 changes: 9 additions & 6 deletions examples/enhanced_udp_relay.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ pause_pool = SOCKS::PausePool.new clearInterval: options.server.pausePool.clearI
# Set Client, Outbound Timeout.

client_timeout = SOCKS::TimeOut.new
client_timeout.read = 15_i32
client_timeout.write = 15_i32
client_timeout.read = 15_i32.seconds
client_timeout.write = 15_i32.seconds

outbound_timeout = SOCKS::TimeOut.new
outbound_timeout.read = 15_i32
outbound_timeout.write = 15_i32
outbound_timeout.read = 15_i32.seconds
outbound_timeout.write = 15_i32.seconds

server.client_timeout = client_timeout
server.outbound_timeout = outbound_timeout
Expand Down Expand Up @@ -116,10 +116,13 @@ end
# Process.

loop do
session = server.accept? rescue nil
next unless session
_socket = server.underly_accept? rescue nil
next unless socket = _socket

spawn do
_session = server.accept socket: socket
next unless session = _session

begin
# Accept client.

Expand Down
15 changes: 9 additions & 6 deletions examples/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pause_pool = SOCKS::PausePool.new clearInterval: options.server.pausePool.clearI
# Set Client, Outbound Timeout.

client_timeout = SOCKS::TimeOut.new
client_timeout.read = 15_i32
client_timeout.write = 15_i32
client_timeout.read = 15_i32.seconds
client_timeout.write = 15_i32.seconds

outbound_timeout = SOCKS::TimeOut.new
outbound_timeout.read = 15_i32
outbound_timeout.write = 15_i32
outbound_timeout.read = 15_i32.seconds
outbound_timeout.write = 15_i32.seconds

server.client_timeout = client_timeout
server.outbound_timeout = outbound_timeout
Expand Down Expand Up @@ -80,10 +80,13 @@ spawn do
end

loop do
session = server.accept? rescue nil
next unless session
_socket = server.underly_accept? rescue nil
next unless socket = _socket

spawn do
_session = server.accept socket: socket
next unless session = _session

begin
session.process_upgrade! server: server, pause_pool: pause_pool
server.handshake! session: session
Expand Down

0 comments on commit 2482a20

Please sign in to comment.