navid/veins / commit
d4509c30298d
Navid M <navidmomtahen@gmail.com> · 2026-11-27
parents: 8a4cd0cbcde1
Browse files at this commit · Download source
--- a/veins/src/cli/fetch_cmd.sx+++ b/veins/src/cli/fetch_cmd.sx@@ -72,6 +72,7 @@ val remote_name: mut bytes.Bytes = bytes.Bytes.dup(bytes.bytes(c"origin", 6)) val path: mut str.StringView = str.from_cstr(c".") val explicit_key: mut bytes.Bytes = bytes.empty()+ val explicit_pin: mut bytes.Bytes = bytes.empty() val have_remote: mut bool = false val i: mut usize = start for i < @len(args) {@@ -85,6 +86,8 @@ stdio.eprint("-key: expects a local key name, not a public key\n", {}) return 1 }+ } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-pin:", 5)) {+ explicit_pin = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len)) } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})@@ -147,8 +150,12 @@ } val pin_opt = remote_config.tls_pin_of(repo, remote_name) val pin: mut bytes.Bytes = bytes.empty()- if pin_opt is some pv {- pin = pv+ if explicit_pin.ptr != none {+ pin = explicit_pin+ } else {+ if pin_opt is some pv {+ pin = pv+ } } val repo_name: bytes.Bytes = client.url_repo_name(url) val c_opt = client.connect_pinned(url, key, repo_name, pin)--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -51,6 +51,7 @@ val remote_name: mut bytes.Bytes = bytes.Bytes.dup(bytes.bytes(c"origin", 6)) val bookmark: mut bytes.Bytes = bytes.empty() val explicit_key: mut bytes.Bytes = bytes.empty()+ val explicit_pin: mut bytes.Bytes = bytes.empty() val path: mut str.StringView = str.from_cstr(c".") val have_remote: mut bool = false val i: mut usize = start@@ -65,6 +66,8 @@ stdio.eprint("-key: expects a local key name, not a public key\n", {}) return 1 }+ } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-pin:", 5)) {+ explicit_pin = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len)) } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})@@ -134,8 +137,12 @@ } val pin_opt = remote_config.tls_pin_of(repo, remote_name) val pin: mut bytes.Bytes = bytes.empty()- if pin_opt is some pv {- pin = pv+ if explicit_pin.ptr != none {+ pin = explicit_pin+ } else {+ if pin_opt is some pv {+ pin = pv+ } } val st: store.Store = store.open_all(repo) val v_opt = state.current_view(repo, st.handles)--- a/veins/src/protocol/client.sx+++ b/veins/src/protocol/client.sx@@ -608,7 +608,7 @@ return some f } none => {- set_error(c, bytes.bytes(c"connection closed while waiting for server response", 45))+ set_error(c, bytes.bytes(c"connection closed while waiting for server response", 51)) return none } }@@ -899,7 +899,7 @@ b3.hasher_final(hash, digest) if good { if !wire.write_frame(c.s, wire.END, rid, bytes.bytes(digest, 32)) {- set_error(c, bytes.bytes(c"connection closed while finishing push", 39))+ set_error(c, bytes.bytes(c"connection closed while finishing push", 38)) good = false } } else {--- a/veins/src/server/serve.sx+++ b/veins/src/server/serve.sx@@ -29,6 +29,7 @@ val stream = use("../net/stream.sx") val net = use("std/net") val allocators = use("std/allocators")+val runtime = use("std/runtime") val wire = use("../protocol/wire.sx") val msg = use("../protocol/messages.sx") val ed = use("../crypto/ed25519.sx")@@ -64,6 +65,14 @@ val out: ref u8 = @alloc(32) as ref u8 @memcpy(out as ref void, id.ptr as ref void, 32) return objid.id(out)+}++/// A client disappearing mid-write must not take the whole server down.+/// Without a handler, POSIX delivers SIGPIPE and the default action terminates+/// the process, which looks like an unexplained connection drop to everyone+/// else. Returning from the handler lets the write fail with EPIPE instead.+fn ignore_sigpipe(_: i32) void = trust {+ return } fn free_bytes_list(xs: list[bytes.Bytes]) void = trust {@@ -416,6 +425,21 @@ } s.client_nonce = bytes.Bytes.dup(h.client_nonce) select_repo(s, root)+ if !s.repo_present && s.hello_repo.len > 0 {+ cmsg.error_prefix()+ stdio.eprint(+ "repository not found: {s}\n",+ {str.view(s.hello_repo.ptr, s.hello_repo.len as i64)}+ )+ wire.write_error(+ s.s,+ f.request_id,+ wire.ERR_NOT_FOUND,+ bytes.bytes(c"repository not found", 20)+ )+ msg.free_hello(h)+ return false+ } if s.repo_present { s.access = access.load(s.repo) if !s.access.valid {@@ -572,6 +596,9 @@ if deny(s, f.request_id, false) { return true }+ // Log before reading state: if the process dies while assembling the+ // response, this line (without a matching "close") localises the failure.+ log_outcome(s, bytes.bytes(c"list-refs", 9)) val v_opt = state.current_view(s.repo, s.handles) val v: mut ref view.View = none match v_opt {@@ -579,6 +606,28 @@ v = x } none => {+ // No operation heads is a legitimate empty repository. Anything+ // else is an unreadable state; answer with an error frame instead+ // of silently pretending the repository is empty.+ val hs: list[objid.Id] = state.heads(s.repo)+ val have_heads: bool = @len(hs) > 0+ for h in hs {+ if h.ptr != none {+ val hp: mut ref void = h.ptr as ref void+ @free(hp)+ }+ }+ @listfree(hs)+ if have_heads {+ wire.write_error(+ s.s,+ f.request_id,+ wire.ERR_INTERNAL,+ bytes.bytes(c"cannot read operation state", 27)+ )+ log_outcome(s, bytes.bytes(c"list-refs-error", 15))+ return true+ } v = state.empty_view() } }@@ -587,34 +636,41 @@ if @len(bm.targets.adds) == 1 { val o = @get(bm.targets.adds, 0) if o is some target {- @append(- out,- msg.RefInfo{- name: bytes.Bytes.dup(bm.name),- target: bytes.Bytes.dup(bytes.bytes(target.ptr, 32)),- change_id: change_id_of(s, target),- kind: 0- }- )+ if target.ptr != none {+ @append(+ out,+ msg.RefInfo{+ name: bytes.Bytes.dup(bm.name),+ target: bytes.Bytes.dup(bytes.bytes(target.ptr, 32)),+ change_id: change_id_of(s, target),+ kind: 0+ }+ )+ } } } } for t in v.tags {- @append(- out,- msg.RefInfo{- name: bytes.Bytes.dup(t.name),- target: bytes.Bytes.dup(bytes.bytes(t.target.ptr, 32)),- change_id: change_id_of(s, t.target),- kind: 1- }- )+ if t.target.ptr != none {+ @append(+ out,+ msg.RefInfo{+ name: bytes.Bytes.dup(t.name),+ target: bytes.Bytes.dup(bytes.bytes(t.target.ptr, 32)),+ change_id: change_id_of(s, t.target),+ kind: 1+ }+ )+ } } view.free_view(v) val body: bytes.Bytes = msg.encode_refs(out) msg.free_refs(out)- log_outcome(s, bytes.bytes(c"list-refs", 9))- return wire.write_frame(s.s, wire.REFS, f.request_id, body)+ val wrote: bool = wire.write_frame(s.s, wire.REFS, f.request_id, body)+ if !wrote {+ log_outcome(s, bytes.bytes(c"list-refs-write-error", 21))+ }+ return wrote } fn handle_negotiate(s: mut ref Session, f: wire.Frame) bool = trust {@@ -1439,6 +1495,12 @@ cert: bytes.Bytes, key: bytes.Bytes ) i32 = trust {+ when linux {+ val _ = runtime.signal(13, ignore_sigpipe)+ }+ when darwin {+ val _ = runtime.signal(13, ignore_sigpipe)+ } val port_opt = parse_port(addr) val port: mut i32 = 0 match port_opt {