···1717 Port int `env:"PORT, default=5555"`
1818 Secret string `env:"SECRET, required"`
1919 DBPath string `env:"DB_PATH, default=knotserver.db"`
2020+ // This disables signature verification so use with caution.
2121+ Dev bool `env:"DEV, default=false"`
2022}
21232224type Config struct {
···1717 }
18181919 _, err = db.Exec(`
2020+ create table if not exists known_dids (
2121+ did text primary key
2222+ );
2023 create table if not exists public_keys (
2124 id integer primary key autoincrement,
2225 did text not null,
2323- name text not null,
2426 key text not null,
2527 created timestamp default current_timestamp,
2626- unique(did, name, key)
2727- );
2828- create table if not exists users (
2929- id integer primary key autoincrement,
3030- did text not null,
3131- unique(did),
3232- foreign key (did) references public_keys(did) on delete cascade
2828+ unique(did, key),
2929+ foreign key (did) references known_dids(did) on delete cascade
3330 );
3131+3432 create table if not exists repos (
3533 id integer primary key autoincrement,
3634 did text not null,
···3939 return nil, fmt.Errorf("failed to start jetstream: %w", err)
4040 }
41414242- // TODO: close this channel and set h.knotInitialized *only after*
4343- // checking if we have an owner.
4444- close(h.init)
4545- h.knotInitialized = true
4242+ // Check if the knot knows about any DIDs;
4343+ // if it does, it is already initialized and we can repopulate the
4444+ // Jetstream subscriptions.
4545+ dids, err := db.GetAllDIDs()
4646+ if err != nil {
4747+ return nil, fmt.Errorf("failed to get all DIDs: %w", err)
4848+ }
4949+ if len(dids) > 0 {
5050+ h.knotInitialized = true
5151+ close(h.init)
5252+ h.js.UpdateDids(dids)
5353+ }
46544755 r.Get("/", h.Index)
4856 r.Route("/{did}", func(r chi.Router) {
···6775 })
6876 })
69777070- // Create a new repository
7878+ // Create a new repository.
7179 r.Route("/repo", func(r chi.Router) {
7280 r.Use(h.VerifySignature)
7381 r.Put("/new", h.NewRepo)
7482 })
75837676- // Add a new user to the knot
7777- r.With(h.VerifySignature).Put("/user", h.AddUser)
8484+ // Initialize the knot with an owner and public key.
7885 r.With(h.VerifySignature).Post("/init", h.Init)
79868087 // Health check. Used for two-way verification with appview.
8188 r.With(h.VerifySignature).Get("/health", h.Health)
82898383- // All public keys on the knot
9090+ // All public keys on the knot.
8491 r.Get("/keys", h.Keys)
85928693 return r, nil
···117124 record := commit["record"].(map[string]interface{})
118125 if err := h.db.AddPublicKeyFromRecord(did, record); err != nil {
119126 log.Printf("failed to add public key: %v", err)
127127+ } else {
128128+ log.Printf("added public key from firehose: %s", data["did"])
120129 }
121121- log.Printf("added public key from firehose: %s", data["did"])
122130 default:
123131 }
124132 }