Skip to content

Commit

Permalink
fix: node connection add missing verack message (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybensacq authored Oct 7, 2024
1 parent eb888a0 commit 7a02c47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/network/peer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub const Peer = struct {
.version => |vm| {
self.protocol_version = @min(self.config.protocol_version, vm.version);
self.services = vm.addr_from.services;
// send verack message
try self.sendVerackMessage();
},

.verack => return,
Expand Down Expand Up @@ -119,6 +121,18 @@ pub const Peer = struct {
);
}

/// Send verack message to peer
fn sendVerackMessage(self: *const Peer) !void {
const verack_message = protocol.messages.VerackMessage{}; // Empty message, as verack doesn't carry data
try wire.sendMessage(
self.allocator,
self.stream.writer(),
self.config.protocol_version,
self.config.network_id,
verack_message,
);
}

pub fn listen(self: *Peer) void {
std.log.info("Listening for messages from {any}", .{self.address});
while (self.should_listen) {
Expand Down
2 changes: 0 additions & 2 deletions src/network/protocol/messages/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ pub fn genericChecksum(m: anytype) [4]u8 {
}

pub fn genericSerialize(m: anytype, allocator: std.mem.Allocator) ![]u8 {
std.debug.print("Type m: {}\n", .{@TypeOf(m)});

comptime {
if (!std.meta.hasMethod(@TypeOf(m), "hintSerializedLen")) @compileError("Expects m to have fn 'hintSerializedLen'.");
if (!std.meta.hasMethod(@TypeOf(m), "serializeToWriter")) @compileError("Expects m to have fn 'serializeToWriter'.");
Expand Down

0 comments on commit 7a02c47

Please sign in to comment.