Artifact b70351aa50a2525f5a9b4a3a2f94c9ca91d2f7af64f7b85913a5dffb8b3e8065:
- File
dst/peer_network.go
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 3287) [annotate] [blame] [check-ins using]
package dst import ( "context" "fmt" "math/rand" "github.com/danmestas/go-libfossil/internal/repo" libsync "github.com/danmestas/go-libfossil/internal/sync" "github.com/danmestas/go-libfossil/internal/xfer" ) // PeerNetwork simulates a peer-to-peer network where each leaf's // Exchange calls HandleSync on the designated peer's repo. No bridge, // no central server — pure leaf-to-leaf sync under DST control. type PeerNetwork struct { rng *rand.Rand peers map[NodeID]*repo.Repo // each leaf's repo dropRate float64 partitions map[NodeID]bool buggify libsync.BuggifyChecker } // NewPeerNetwork creates a simulated peer network. func NewPeerNetwork(rng *rand.Rand) *PeerNetwork { if rng == nil { panic("dst.NewPeerNetwork: rng must not be nil") } return &PeerNetwork{ rng: rng, peers: make(map[NodeID]*repo.Repo), partitions: make(map[NodeID]bool), } } // AddPeer registers a leaf's repo as a sync target for other leaves. func (n *PeerNetwork) AddPeer(id NodeID, r *repo.Repo) { if r == nil { panic("PeerNetwork.AddPeer: r must not be nil") } n.peers[id] = r } // SetDropRate sets the probability that any message is dropped. func (n *PeerNetwork) SetDropRate(rate float64) { n.dropRate = rate } // SetBuggify configures fault injection for the handler. func (n *PeerNetwork) SetBuggify(b libsync.BuggifyChecker) { n.buggify = b } // Partition isolates a node — all messages to/from it are dropped. func (n *PeerNetwork) Partition(id NodeID) { n.partitions[id] = true } // Heal removes a node from the partition set. func (n *PeerNetwork) Heal(id NodeID) { delete(n.partitions, id) } // HealAll removes all partitions. func (n *PeerNetwork) HealAll() { n.partitions = make(map[NodeID]bool) } // Transport returns a sync.Transport for the given source node that // routes to a specific target peer's HandleSync. func (n *PeerNetwork) Transport(source, target NodeID) *PeerTransport { return &PeerTransport{ network: n, source: source, target: target, } } // exchange handles a message from source to target, applying fault injection. func (n *PeerNetwork) exchange(ctx context.Context, source, target NodeID, req *xfer.Message) (*xfer.Message, error) { if n.partitions[source] { return nil, fmt.Errorf("peernet: source %s is partitioned", source) } if n.partitions[target] { return nil, fmt.Errorf("peernet: target %s is partitioned", target) } if n.dropRate > 0 && n.rng.Float64() < n.dropRate { return nil, fmt.Errorf("peernet: message from %s to %s dropped", source, target) } r, ok := n.peers[target] if !ok { return nil, fmt.Errorf("peernet: unknown target %s", target) } return libsync.HandleSyncWithOpts(ctx, r, req, libsync.HandleOpts{ Buggify: n.buggify, }) } // PeerTransport implements sync.Transport by routing through the PeerNetwork // to a specific target peer. type PeerTransport struct { network *PeerNetwork source NodeID target NodeID } // Exchange sends a request through the peer network to the target's HandleSync. func (t *PeerTransport) Exchange(ctx context.Context, req *xfer.Message) (*xfer.Message, error) { if req == nil { panic("PeerTransport.Exchange: req must not be nil") } return t.network.exchange(ctx, t.source, t.target, req) }