updated to new onyx syntax
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 15 Apr 2023 03:01:27 +0000 (22:01 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 15 Apr 2023 03:01:27 +0000 (22:01 -0500)
example/udp_client.onyx
example/udp_server.onyx
module.onyx
src/host.onyx
src/packet.onyx
src/peer.onyx

index 587748f297862cefa5f4fb588e3a16b71157698b..f63dc8ee63dc527f17f370150cf31869306fbdca 100644 (file)
@@ -1,8 +1,8 @@
 #load "core/std"
 #load "./../module"
 
-use package core
-onyx_net :: package onyx_net
+use core {*}
+use onyx_net
 
 octets_to_addr :: (a, b, c, d: u8) -> u32 {
     return (cast(u32) a << 24) |
@@ -17,18 +17,17 @@ main :: (args) => {
     // to a port. Only 1 peer is needed, as this is only connecting
     // to one server.
     host: ^onyx_net.Host;
-    if host', err := onyx_net.host_create(null, 1); err != .None {
+    if host~, err := onyx_net.host_create(null, 1); err != .None {
         println(err);
     }
 
     addr: net.Socket_Address;
-    addr.addr = octets_to_addr(127, 0, 0, 1);
-    addr.port = 8080;
+    net.make_ipv4_address(&addr, 0x7f000001, 8080);
     peer := onyx_net.host_connect(host, ^addr, 2);
 
     input_thread: thread.Thread;
     thread.spawn(^input_thread, peer, (peer) => {
-        input_reader := io.reader_make(^stdio_stream);
+        input_reader := io.reader_make(^stdio.stream);
 
         while true {
             line := io.read_line(^input_reader) |> string.strip_whitespace();
index 344f32aab2fd03cf1bc1b296c17d37c95faf204a..521007eb2672482bb5292b28f2df8d0906e5712a 100644 (file)
@@ -1,8 +1,8 @@
 #load "core/std"
 #load "./../module"
 
-use package core
-onyx_net :: package onyx_net
+use core {*}
+use onyx_net
 
 
 main :: (args) => {
index 8e298ebf10dbddd091353b60c863e74ed64233b2..273ff684dd30a7332ce817b138ed39bc33d425db 100644 (file)
@@ -1,16 +1,18 @@
 package onyx_net
 
 #package {
-    array  :: package core.array
-    net    :: package core.net
-    list   :: package core.list
-    alloc  :: package core.alloc
-    memory :: package core.memory
-    string :: package core.string
-    random :: package core.random
-    os     :: package core.os
-    math   :: package core.math
-    iter   :: package core.iter
+    use core {*}
+
+    array  :: array
+    net    :: net
+    list   :: list
+    alloc  :: alloc
+    memory :: memory
+    string :: string
+    random :: random
+    os     :: os
+    math   :: math
+    iter   :: iter
 }
 
 #load_all "./src"
index 5d642c93052a0f787dda9fc2a964f0fc116110d1..e4d94c94351e0c25c8bffa883c39f0d3ce840c46 100644 (file)
@@ -1,7 +1,5 @@
 package onyx_net
 
-// @CLEANUP
-use package core
 
 Host :: struct {
     socket : net.Socket;
@@ -33,13 +31,13 @@ Host :: struct {
     Socket_Binding_Failed;
 }
 
-host_create :: (addr: ^net.Socket_Address, peer_count: u32) -> (^Host, Host_Creation_Error) {
+host_create :: (addr: &net.Socket_Address, peer_count: u32) -> (&Host, Host_Creation_Error) {
     errored := false;
     host := new(Host);
     defer if errored do cfree(host);
 
     host.peers = make([] Peer, peer_count);
-    defer if errored do delete(^host.peers);
+    defer if errored do delete(&host.peers);
     host.connected_peers = 0;
 
     if socket, err := net.socket_create(.Inet, .Dgram); err != .None {
@@ -49,12 +47,12 @@ host_create :: (addr: ^net.Socket_Address, peer_count: u32) -> (^Host, Host_Crea
     } else {
         host.socket = socket;
     }
-    defer if errored do net.socket_close(^host.socket);
+    defer if errored do net.socket_close(&host.socket);
 
     if addr != null {
         sa: net.Socket_Address;
-        net.make_ipv4_address(^sa, 0, addr.port);
-        if !(host.socket->bind(^sa)) {
+        net.make_ipv4_address(&sa, 0, addr.port);
+        if !(host.socket->bind(&sa)) {
             errored = true;
             return null, .Socket_Binding_Failed;
         }
@@ -69,7 +67,7 @@ host_create :: (addr: ^net.Socket_Address, peer_count: u32) -> (^Host, Host_Crea
     host.no_ack_disconnect_timeout = 10000;
     host.current_time = ~~ (os.time() & cast(u64) 0xFFFFFFFF);
 
-    for^ peer: host.peers {
+    for& peer: host.peers {
         peer.host = host;
         peer.state = .Disconnected;
         peer.channels = .{ null, 0 };
@@ -82,11 +80,11 @@ host_create :: (addr: ^net.Socket_Address, peer_count: u32) -> (^Host, Host_Crea
     return host, .None;
 }
 
-host_connect :: (host: ^Host, addr: ^net.Socket_Address, channel_count: u32) -> ^Peer {
-    peer: ^Peer;
+host_connect :: (host: &Host, addr: &net.Socket_Address, channel_count: u32) -> &Peer {
+    peer: &Peer;
 
     // Find first peer that is in the disconnected state.
-    for^ host.peers do if it.state == .Disconnected {
+    for& host.peers do if it.state == .Disconnected {
         peer = it;
         break;
     }
@@ -101,7 +99,7 @@ host_connect :: (host: ^Host, addr: ^net.Socket_Address, channel_count: u32) ->
     peer.mtu = Host_Default_MTU;
     peer.last_acknowledge_time = host.current_time;
 
-    for^ peer.channels do peer_setup_channel(peer, it);
+    for& peer.channels do peer_setup_channel(peer, it);
 
     command := new(Protocol_Connect);
     command.command = .Connect;
@@ -117,21 +115,21 @@ host_connect :: (host: ^Host, addr: ^net.Socket_Address, channel_count: u32) ->
     return peer;
 }
 
-host_free :: (host: ^Host) {
-    net.socket_close(^host.socket);
-    delete(^host.peers);
-    delete(host);
+host_free :: (host: &Host) {
+    net.socket_close(&host.socket);
+    delete(&host.peers);
+    cfree(host);
 }
 
-host_broadcast :: (host: ^Host, channel: Channel_ID, packet: ^Packet) {
-    for ^peer: host.peers {
+host_broadcast :: (host: &Host, channel: Channel_ID, packet: &Packet) {
+    for &peer: host.peers {
         if peer.state != .Connected do continue;
 
         peer_send(peer, channel, packet);
     }
 }
 
-host_pulse :: (host: ^Host, timeout: u32 = 0) -> bool {
+host_pulse :: (host: &Host, timeout: u32 = 0) -> bool {
     host.produced_event = false;
     host.current_time = ~~ (os.time() & cast(u64) 0xFFFFFFFF);
 
@@ -141,8 +139,8 @@ host_pulse :: (host: ^Host, timeout: u32 = 0) -> bool {
     return host.produced_event;
 }
 
-host_send_commands :: (host: ^Host) -> bool {
-    for ^peer: host.peers {
+host_send_commands :: (host: &Host) -> bool {
+    for &peer: host.peers {
         //
         // Skip over peers that are dead or disconnected.
         if peer.state == .Disconnected || peer.state == .Zombie {
@@ -186,9 +184,9 @@ host_send_commands :: (host: ^Host) -> bool {
     }
 }
 
-host_receive_commands :: (host: ^Host, timeout: u32 = 0) -> bool {
+host_receive_commands :: (host: &Host, timeout: u32 = 0) -> bool {
     if timeout > 0 {
-        check_sockets := (^net.Socket).[ ^host.socket ];
+        check_sockets := (&net.Socket).[ &host.socket ];
         changed_buffer := alloc.array_from_stack(net.Socket_Poll_Status, 1);
         net.socket_poll_all(check_sockets, timeout, changed_buffer);
 
@@ -204,26 +202,26 @@ host_receive_commands :: (host: ^Host, timeout: u32 = 0) -> bool {
     return host_handle_incoming_commands(host);
 }
 
-host_handle_incoming_commands :: (host: ^Host) -> bool {
-    header: ^Protocol_Header = ~~ host.received_data.data;
+host_handle_incoming_commands :: (host: &Host) -> bool {
+    header: &Protocol_Header = ~~ host.received_data.data;
     current_data := host.received_data;
 
     peer_id := cast(u32) net.network_to_host(header.peer_id);
-    peer: ^Peer;
+    peer: &Peer;
 
     if peer_id == 0xffff ---   // a Peer Id of 0xffff is used for a newly connecting peer.
     elseif peer_id >= host.peers.count || peer_id >= host.peers.count {
         return false;
 
     } else {
-        peer = ^host.peers[peer_id];
+        peer = &host.peers[peer_id];
     }
 
     if peer != null {
         if peer.addr.port != host.received_addr.port do return false;
     }
 
-    string.advance(^current_data, sizeof typeof *header);
+    string.advance(&current_data, sizeof typeof *header);
 
     return_block :: macro () {
         return host.event.type != .None;
@@ -232,12 +230,12 @@ host_handle_incoming_commands :: (host: ^Host) -> bool {
     while current_data.count >= sizeof Protocol_Command_Header {
         if host.produced_event do break;
 
-        command := cast(^Protocol_Command_Header) current_data.data;
+        command := cast(&Protocol_Command_Header) current_data.data;
         command_id := command_get_effective(command.command);
         command.seq_number = net.network_to_host(command.seq_number);
 
         // printf("Received command: {} {} {*p}\n", command_sizes[command_id], cast(Command) command_id, command);
-        string.advance(^current_data, command_sizes[command_id]);
+        string.advance(&current_data, command_sizes[command_id]);
 
         switch command_id {
             case .Acknowledge {
@@ -267,12 +265,12 @@ host_handle_incoming_commands :: (host: ^Host) -> bool {
 
             case .Send_Reliable, .Send_Unreliable {
                 if peer == null do return_block();
-                host_handle_send_reliable_command(host, peer, ~~ command, ^current_data);
+                host_handle_send_reliable_command(host, peer, ~~ command, &current_data);
             }
 
             case .Send_Fragment {
                 if peer == null do return_block();
-                host_handle_send_fragment_command(host, peer, ~~ command, ^current_data);
+                host_handle_send_fragment_command(host, peer, ~~ command, &current_data);
             }
         }
 
@@ -296,15 +294,15 @@ host_handle_incoming_commands :: (host: ^Host) -> bool {
     return host.produced_event;
 }
 
-host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
+host_get_events :: (host: &Host, timeout: u32 = 0) -> Iterator(&Event) {
     Context :: struct {
-        host: ^Host;
+        host: &Host;
         timeout: u32 = 0;
     }
 
-    next :: (use ctx: ^Context) -> (^Event, bool) {
+    next :: (use ctx: &Context) -> (&Event, bool) {
         if host_pulse(host, timeout) {
-            return ^host.event, true;
+            return &host.event, true;
         }
 
         return null, false;
@@ -316,7 +314,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     return .{ ctx, next, cfree };
 }
 
-#local host_notify_connect :: (host: ^Host, peer: ^Peer) {
+#local host_notify_connect :: (host: &Host, peer: &Peer) {
     host.event.type = .Connection;
     host.event.peer = peer;
     host.event.channel_id = 255; // Magic constant
@@ -326,7 +324,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     host.produced_event = true;
 }
 
-#local host_notify_disconnect :: (host: ^Host, peer: ^Peer) {
+#local host_notify_disconnect :: (host: &Host, peer: &Peer) {
     host.event.type = .Disconnection;
     host.event.peer = peer;
     host.event.channel_id = 255; // Magic constant
@@ -336,7 +334,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     host.produced_event = true;
 }
 
-#local host_notify_message :: (host: ^Host, peer: ^Peer, channel_id: u8, data: [] u8) {
+#local host_notify_message :: (host: &Host, peer: &Peer, channel_id: u8, data: [] u8) {
     host.event.type = .Message;
     host.event.peer = peer;
     host.event.channel_id = channel_id;
@@ -346,7 +344,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     host.produced_event = true;
 }
 
-#local host_handle_acknowledge_command :: (host: ^Host, peer: ^Peer, command: ^Protocol_Acknowledge) {
+#local host_handle_acknowledge_command :: (host: &Host, peer: &Peer, command: &Protocol_Acknowledge) {
     if peer.state == .Disconnected || peer.state == .Zombie do return;
 
     //
@@ -409,10 +407,10 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     }
 }
 
-#local host_handle_connect_command :: (host: ^Host, command: ^Protocol_Connect) -> ^Peer {
-    peer: ^Peer;
+#local host_handle_connect_command :: (host: &Host, command: &Protocol_Connect) -> &Peer {
+    peer: &Peer;
 
-    for^ host.peers {
+    for& host.peers {
         if it.state == .Disconnected {
             peer = it;
             break;
@@ -426,7 +424,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
 
     channel_count := net.network_to_host(command.channel_count);
     peer.channels = make([] Channel, channel_count);
-    for ^peer.channels do peer_setup_channel(peer, it);
+    for &peer.channels do peer_setup_channel(peer, it);
 
     peer.state = .Acknowledging_Connection;
     peer.connect_id = net.network_to_host(command.connect_id);
@@ -450,7 +448,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     return peer;
 }
 
-#local host_handle_verify_connect_command :: (host: ^Host, peer: ^Peer, command: ^Protocol_Verify_Connect) {
+#local host_handle_verify_connect_command :: (host: &Host, peer: &Peer, command: &Protocol_Verify_Connect) {
     if net.network_to_host(command.connect_id) != peer.connect_id do return;
 
     channel_count := net.network_to_host(command.channel_count);
@@ -471,14 +469,14 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     return;
 }
 
-#local host_handle_disconnect_command :: (host: ^Host, peer: ^Peer, command: ^Protocol_Disconnect) {
+#local host_handle_disconnect_command :: (host: &Host, peer: &Peer, command: &Protocol_Disconnect) {
     peer.state = .Disconnected;
     host_notify_disconnect(host, peer);
 }
 
 //
 // This is slightly misnamed, as it is actually handling a received reliable message.
-#local host_handle_send_reliable_command :: (host: ^Host, peer: ^Peer, command: ^Protocol_Send, data: ^[] u8) {
+#local host_handle_send_reliable_command :: (host: &Host, peer: &Peer, command: &Protocol_Send, data: &[] u8) {
     if ~~command.channel > peer.channels.count || (peer.state != .Connected && peer.state != .Disconnect_Later) {
         return;
     }
@@ -490,7 +488,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     defer string.advance(data, data_length);
 
     if command_get_effective(command.command) == .Send_Reliable {
-        channel := ^peer.channels[command.channel];
+        channel := &peer.channels[command.channel];
         for channel.reliable_windows {
             if command.seq_number == it do return;
         }
@@ -503,7 +501,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     host_notify_message(host, peer, command.channel, *data);
 }
 
-#local host_handle_send_fragment_command :: (host: ^Host, peer: ^Peer, command: ^Protocol_Send_Fragment, data: ^[] u8) {
+#local host_handle_send_fragment_command :: (host: &Host, peer: &Peer, command: &Protocol_Send_Fragment, data: &[] u8) {
     if ~~command.channel > peer.channels.count || (peer.state != .Connected && peer.state != .Disconnect_Later) {
         return;
     }
@@ -515,7 +513,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     defer string.advance(data, data_length);
 
     // @CopyPaste
-    channel := ^peer.channels[command.channel];
+    channel := &peer.channels[command.channel];
     for channel.reliable_windows {
         if command.seq_number == it do return;
     }
@@ -525,10 +523,10 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     channel.reliable_windows_cursor %= channel.reliable_windows.count;
 
     fragment_id := net.network_to_host(command.fragment_id);
-    fragment: ^Fragmented_Data = array.first(channel.pending_fragments, #(it.fragment_id == fragment_id));
+    fragment: &Fragmented_Data = array.first(channel.pending_fragments, #(it.fragment_id == fragment_id));
 
     if fragment == null {
-        fragment = array.alloc_one(^channel.pending_fragments);
+        fragment = array.alloc_one(&channel.pending_fragments);
         fragment.fragment_id = fragment_id;
         fragment.fragments_remaining = net.network_to_host(command.fragment_count);
         fragment.data = make([] u8, net.network_to_host(command.total_length));
@@ -540,7 +538,7 @@ host_get_events :: (host: ^Host, timeout: u32 = 0) -> Iterator(^Event) {
     if fragment.fragments_remaining == 0 {
         host_notify_message(host, peer, command.channel, fragment.data);
 
-        for iter.as_iter(^channel.pending_fragments, by_pointer=true) {
+        for iter.as_iter(&channel.pending_fragments, by_pointer=true) {
             if it.fragment_id == fragment_id {
                 #remove;
                 break;
@@ -560,7 +558,7 @@ Event :: struct {
     }
 
     type: Type;
-    peer: ^Peer;
+    peer: &Peer;
     channel_id: Channel_ID;
     timestamp: u32;
     data: [] u8;
index 8b251fccc1c6b0b5eac7b0c5eb8ad228429cd196..16b6ca8f7702792886200cfd0e979e343b7cc060 100644 (file)
@@ -1,8 +1,8 @@
 package onyx_net
 
 Outgoing_Command :: struct {
-    command: ^Protocol_Command_Header;
-    packet : ^Packet;
+    command: &Protocol_Command_Header;
+    packet : &Packet;
     reliable_seq_number   : u16;
     unreliable_seq_number : u16;
     sent_time             : u32;
@@ -12,8 +12,8 @@ Outgoing_Command :: struct {
 }
 
 Incoming_Command :: struct {
-    command: ^Protocol_Command_Header;
-    packet : ^Packet;
+    command: &Protocol_Command_Header;
+    packet : &Packet;
     reliable_seq_number   : u16;
     unreliable_seq_number : u16;
 }
@@ -40,11 +40,11 @@ Packet :: struct {
 
 Acknowledgement :: struct {
     sent_time: u16;
-    command: ^Protocol_Command_Header;
+    command: &Protocol_Command_Header;
 }
 
 
-outgoing_command_pack_into_buffer :: (out: ^Outgoing_Command, peer: ^Peer, buf: [] u8) -> ([] u8, bool) {
+outgoing_command_pack_into_buffer :: (out: &Outgoing_Command, peer: &Peer, buf: [] u8) -> ([] u8, bool) {
     write_offset := 0;
     write :: macro (data: [] u8) {
         if write_offset + data.count > buf.count do return .[], false;
@@ -63,16 +63,16 @@ outgoing_command_pack_into_buffer :: (out: ^Outgoing_Command, peer: ^Peer, buf:
         header.peer_id = 65535;
     }
 
-    write((cast(^u8) ^header)[0 .. sizeof typeof header]);
+    write((cast([&]u8) &header)[0 .. sizeof typeof header]);
 
     command_size := command_sizes[~~ command_get_effective(out.command.command)];
-    write((cast(^u8) out.command)[0 .. command_size]);
+    write((cast([&]u8) out.command)[0 .. command_size]);
 
     if out.packet != null {
         if command_get_effective(out.command.command) == .Send_Fragment {
             //
             // Converting to network byte order just to switch back here is a little silly...
-            fragment := cast(^Protocol_Send_Fragment) out.command;
+            fragment := cast(&Protocol_Send_Fragment) out.command;
             start := cast(u32) net.network_to_host(fragment.fragment_offset);
             end   := start + ~~net.network_to_host(fragment.data_length);
 
index a3183be172ef6e7018ed24d43e466da59ecf4919..3cbf7a0194155e4e21230bd17b0e020fcd0eede2 100644 (file)
@@ -14,7 +14,7 @@ Peer_State :: enum {
 }
 
 Peer :: struct {
-    host: ^Host;
+    host: &Host;
     state: Peer_State;
     addr: net.Socket_Address;
 
@@ -49,19 +49,19 @@ Peer :: struct {
     incoming_reliable_seq_number: u16;
     outgoing_unsequenced_group:   u32;
 
-    outgoing_commands: [..] ^Outgoing_Command;
-    incoming_commands: [..] ^Incoming_Command;
+    outgoing_commands: [..] &Outgoing_Command;
+    incoming_commands: [..] &Incoming_Command;
     acknowledgements:  [..] Acknowledgement;
-    sent_reliable_commands: [..] ^Outgoing_Command;
+    sent_reliable_commands: [..] &Outgoing_Command;
 }
 
-peer_destroy :: (peer: ^Peer) {
-    if peer.channels.data != null          do delete(^peer.channels);
-    if peer.outgoing_commands.data != null do delete(^peer.outgoing_commands);
-    if peer.incoming_commands.data != null do delete(^peer.incoming_commands);
+peer_destroy :: (peer: &Peer) {
+    if peer.channels.data != null          do delete(&peer.channels);
+    if peer.outgoing_commands.data != null do delete(&peer.outgoing_commands);
+    if peer.incoming_commands.data != null do delete(&peer.incoming_commands);
 }
 
-peer_disconnect :: (peer: ^Peer) {
+peer_disconnect :: (peer: &Peer) {
     if peer.state == .Disconnected do return;
 
     peer.state = .Disconnected;
@@ -69,7 +69,7 @@ peer_disconnect :: (peer: ^Peer) {
     peer_destroy(peer);
 }
 
-peer_setup_channel :: (peer: ^Peer, channel: ^Channel) {
+peer_setup_channel :: (peer: &Peer, channel: &Channel) {
     channel.id = ~~((cast(u32) channel - cast(u32) peer.channels.data) / 4);
     channel.outgoing_reliable_seq_number = 0;
     channel.reliable_windows_cursor = 0;
@@ -80,7 +80,7 @@ peer_setup_channel :: (peer: ^Peer, channel: ^Channel) {
 }
 
 peer_queue_outgoing_command :: #match {
-    (peer: ^Peer, command: ^Protocol_Command_Header, packet: ^Packet = null) -> ^Outgoing_Command {
+    (peer: &Peer, command: &Protocol_Command_Header, packet: &Packet = null) -> &Outgoing_Command {
         out := new(Outgoing_Command);
         out.command = command;
         out.packet = packet;
@@ -91,14 +91,14 @@ peer_queue_outgoing_command :: #match {
     }
 }
 
-peer_setup_outgoing_command :: (peer: ^Peer, command: ^Outgoing_Command) {
+peer_setup_outgoing_command :: (peer: &Peer, command: &Outgoing_Command) {
     if command.command.channel == 255 {
         peer.outgoing_reliable_seq_number += 1;
         command.reliable_seq_number = peer.outgoing_reliable_seq_number;
         command.unreliable_seq_number = 0;
 
     } else {
-        channel := ^peer.channels[command.command.channel];
+        channel := &peer.channels[command.command.channel];
         
         // Oof... That's a long chain of command.
         if (command.command.command & .Flag_Acknowledge) != 0 {
@@ -126,12 +126,12 @@ peer_setup_outgoing_command :: (peer: ^Peer, command: ^Outgoing_Command) {
     peer.outgoing_commands << command;
 }
 
-peer_send :: (peer: ^Peer, channel_id: Channel_ID, packet: ^Packet) -> bool {
+peer_send :: (peer: &Peer, channel_id: Channel_ID, packet: &Packet) -> bool {
     if peer.state != .Connected || ~~channel_id > peer.channels.count {
         return false;
     }
 
-    channel := ^peer.channels[channel_id];
+    channel := &peer.channels[channel_id];
 
     if packet.data.count > peer.mtu - sizeof Protocol_Header - sizeof Protocol_Send {
         data_per_packet := peer.mtu - sizeof Protocol_Header - sizeof Protocol_Send_Fragment;
@@ -182,12 +182,12 @@ peer_send :: (peer: ^Peer, channel_id: Channel_ID, packet: ^Packet) -> bool {
     return peer_queue_outgoing_command(peer, command, packet) != null;
 }
 
-peer_queue_acknowledgement :: (peer: ^Peer, command: ^Protocol_Command_Header, sent_time: u16) {
+peer_queue_acknowledgement :: (peer: &Peer, command: &Protocol_Command_Header, sent_time: u16) {
     peer.acknowledgements << .{ sent_time, command };
 }
 
-peer_check_outgoing_commands :: (peer: ^Peer) {
-    for iter.as_iter(^peer.sent_reliable_commands) {
+peer_check_outgoing_commands :: (peer: &Peer) {
+    for iter.as_iter(&peer.sent_reliable_commands) {
         time_diff := math.abs(cast(i64) it.sent_time - cast(i64) peer.host.current_time);
         if time_diff >= ~~ peer.no_ack_resend_timeout {
             peer.outgoing_commands << it;
@@ -196,7 +196,7 @@ peer_check_outgoing_commands :: (peer: ^Peer) {
     }
 }
 
-peer_flush_outgoing_commands :: (peer: ^Peer) -> i32 {
+peer_flush_outgoing_commands :: (peer: &Peer) -> i32 {
     send_buffer := alloc.array_from_stack(u8, 65535);
 
     total_sent := 0;
@@ -207,7 +207,7 @@ peer_flush_outgoing_commands :: (peer: ^Peer) -> i32 {
         to_send, success := it->pack_into_buffer(peer, send_buffer);
         if !success do continue;
 
-        sent_bytes := peer.host.socket->sendto(to_send, ^peer.addr);
+        sent_bytes := peer.host.socket->sendto(to_send, &peer.addr);
         if sent_bytes < 0 {
             return -1;
         }
@@ -222,16 +222,16 @@ peer_flush_outgoing_commands :: (peer: ^Peer) -> i32 {
         }
     }
 
-    array.clear(^peer.outgoing_commands);
+    array.clear(&peer.outgoing_commands);
     return total_sent;
 }
 
-peer_send_acknowledgements :: (peer: ^Peer) {
+peer_send_acknowledgements :: (peer: &Peer) {
     send_buffer: [65535] u8;
 
     bytes_to_be_sent := 0;
 
-    for ^ack: peer.acknowledgements {
+    for &ack: peer.acknowledgements {
         seq_num := net.host_to_network(ack.command.seq_number);
 
         command: Protocol_Acknowledge;
@@ -242,7 +242,7 @@ peer_send_acknowledgements :: (peer: ^Peer) {
         command.recv_sent_time = net.host_to_network(ack.sent_time);
 
         out: Outgoing_Command;
-        out.command = ^command;
+        out.command = &command;
         
         to_send, success := out->pack_into_buffer(peer, send_buffer[bytes_to_be_sent..65535]);
         if !success do continue;
@@ -250,7 +250,7 @@ peer_send_acknowledgements :: (peer: ^Peer) {
         bytes_to_be_sent += to_send.count;
         
         if bytes_to_be_sent >= peer.mtu - sizeof Protocol_Acknowledge {
-            sent_bytes := peer.host.socket->sendto(send_buffer[0 .. bytes_to_be_sent], ^peer.addr);
+            sent_bytes := peer.host.socket->sendto(send_buffer[0 .. bytes_to_be_sent], &peer.addr);
             if sent_bytes < 0 do return;
 
             bytes_to_be_sent = 0;
@@ -258,14 +258,14 @@ peer_send_acknowledgements :: (peer: ^Peer) {
     }
 
     if bytes_to_be_sent > 0 {
-        sent_bytes := peer.host.socket->sendto(send_buffer[0 .. bytes_to_be_sent], ^peer.addr);
+        sent_bytes := peer.host.socket->sendto(send_buffer[0 .. bytes_to_be_sent], &peer.addr);
         if sent_bytes < 0 do return;
     }
 
-    array.clear(^peer.acknowledgements);
+    array.clear(&peer.acknowledgements);
 }
 
-peer_send_ping :: (peer: ^Peer) {
+peer_send_ping :: (peer: &Peer) {
     for peer.sent_reliable_commands {
         if command_get_effective(it.command.command) == .Ping do return;
     }
@@ -281,16 +281,16 @@ peer_send_ping :: (peer: ^Peer) {
     peer_queue_outgoing_command(peer, ping);
 }
 
-peer_send_disconnect :: (peer: ^Peer) {
+peer_send_disconnect :: (peer: &Peer) {
     disconnect := new(Protocol_Disconnect);
     disconnect.command = .Disconnect;
     disconnect.channel = 255;
     peer_queue_outgoing_command(peer, disconnect);
 }
 
-peer_remove_sent_reliable_command :: (peer: ^Peer, seq_num: u16, channel: Channel_ID) -> Command {
-    command: ^Outgoing_Command;
-    for iter.as_iter(^peer.sent_reliable_commands) {
+peer_remove_sent_reliable_command :: (peer: &Peer, seq_num: u16, channel: Channel_ID) -> Command {
+    command: &Outgoing_Command;
+    for iter.as_iter(&peer.sent_reliable_commands) {
         if it.reliable_seq_number == seq_num && it.command.channel == channel {
             command = it;
             #remove;
@@ -304,7 +304,7 @@ peer_remove_sent_reliable_command :: (peer: ^Peer, seq_num: u16, channel: Channe
     return command_get_effective(command.command.command);
 }
 
-peer_free_outgoing_command :: (peer: ^Peer, command: ^Outgoing_Command) {
+peer_free_outgoing_command :: (peer: &Peer, command: &Outgoing_Command) {
     if command.packet != null {
         command.packet.reference_count -= 1;
         if command.packet.reference_count <= 0 {