{"id":15438024,"url":"https://github.com/mudler/go-libp2p-simple-raft","last_synced_at":"2026-02-17T05:30:56.112Z","repository":{"id":257538764,"uuid":"840199709","full_name":"mudler/go-libp2p-simple-raft","owner":"mudler","description":"A simple raft wrapper for libp2p","archived":false,"fork":false,"pushed_at":"2025-01-14T12:11:50.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T03:41:39.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mudler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-09T07:19:43.000Z","updated_at":"2025-02-18T16:32:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"7140d3a7-172c-49b9-807c-2f3bef447a4b","html_url":"https://github.com/mudler/go-libp2p-simple-raft","commit_stats":null,"previous_names":["mudler/go-libp2p-simple-raft"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2Fgo-libp2p-simple-raft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2Fgo-libp2p-simple-raft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2Fgo-libp2p-simple-raft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2Fgo-libp2p-simple-raft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mudler","download_url":"https://codeload.github.com/mudler/go-libp2p-simple-raft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249765196,"owners_count":21322376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T19:00:21.223Z","updated_at":"2026-02-17T05:30:51.092Z","avatar_url":"https://github.com/mudler.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-libp2p-simple-raft\n\nA simple raft wrapper for libp2p.\n\nMotivation: I wanted to experiment and have a simple wrapper to work with raft and libp2p, hence why this.\n\n### Usage\n\n```go\nimport (\n    \"github.com/mudler/go-libp2p-simple-raft\"\n)\n\n// Structure nodes have to agree on\ntype raftState struct {\n    Value int\n}\n\nctx := context.Background()\n\n// start a libp2p node (not done here)\n\n// NewSimpleRaft needs a libp2p host, a state to calculate consensus on, and a channel to listen for new peers that are discovered\nw, err := simpleraft.NewSimpleRaft(ctx, h, \u0026raftState{Value: 3}, peerChan)\nif err != nil {\n    fmt.Println(err)\n}\n\n// Make sure states are syncronized\nerr = w.WaitForSync(ctx)\nif err != nil {\n    fmt.Println(err)\n}\n\n// Check if we are leaders and update state\nif !w.IsLeader() {\n    // we are not leaders, we can only read the state and/or know who is the leader\n    state, err:= w.GetState()\n    address, serverID := w.GetLeaderID()\n    return\n}\n\n// verify we are leaders\nif err := w.VerifyLeader(); err != nil {\n    fmt.Println(\"error\", err)\n}\n\n// try to write the state\nnUpdates := 0\nfor {\n    if nUpdates \u003e= 1000 {\n        break\n    }\n\n    newState := \u0026raftState{nUpdates * 2}\n\n    // CommitState() blocks until the state has been\n    // agreed upon by everyone\n    agreedState, err := w.CommitState(newState)\n    if err != nil {\n        fmt.Println(err)\n        continue\n    }\n    if agreedState == nil {\n        fmt.Println(\"agreedState is nil: commited on a non-leader?\")\n        continue\n    }\n    agreedRaftState := agreedState.(*raftState)\n    nUpdates++\n\n    if nUpdates%200 == 0 {\n        fmt.Printf(\"Performed %d updates. Current state value: %d\\n\",\n            nUpdates, agreedRaftState.Value)\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudler%2Fgo-libp2p-simple-raft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmudler%2Fgo-libp2p-simple-raft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudler%2Fgo-libp2p-simple-raft/lists"}