Signed-off-by: Seongmin Lee git@boltless.me
+58
-10
Diff
round #1
+17
-5
knotmirror/models/models.go
+17
-5
knotmirror/models/models.go
···
85
85
HostStatusBanned,
86
86
}
87
87
88
+
func (h *Host) URL() string {
89
+
if h.NoSSL {
90
+
return fmt.Sprintf("http://%s", h.Hostname)
91
+
} else {
92
+
return fmt.Sprintf("https://%s", h.Hostname)
93
+
}
94
+
}
95
+
96
+
func (h *Host) WsURL() string {
97
+
if h.NoSSL {
98
+
return fmt.Sprintf("ws://%s", h.Hostname)
99
+
} else {
100
+
return fmt.Sprintf("wss://%s", h.Hostname)
101
+
}
102
+
}
103
+
88
104
// func (h *Host) SubscribeGitRefsURL(cursor int64) string {
89
105
// scheme := "wss"
90
106
// if h.NoSSL {
···
98
114
// }
99
115
100
116
func (h *Host) LegacyEventsURL(cursor int64) string {
101
-
scheme := "wss"
102
-
if h.NoSSL {
103
-
scheme = "ws"
104
-
}
105
-
u := fmt.Sprintf("%s://%s/events", scheme, h.Hostname)
117
+
u := fmt.Sprintf("%s/events", h.WsURL())
106
118
if cursor > 0 {
107
119
u = fmt.Sprintf("%s?cursor=%d", u, cursor)
108
120
}
+17
-2
knotmirror/tapclient.go
+17
-2
knotmirror/tapclient.go
···
8
8
"log/slog"
9
9
"net/netip"
10
10
"net/url"
11
+
"strings"
11
12
"time"
12
13
13
14
"tangled.org/core/api/tangled"
···
78
79
return fmt.Errorf("parsing record: %w", err)
79
80
}
80
81
82
+
knotUrl := record.Knot
83
+
if !strings.Contains(record.Knot, "://") {
84
+
if host, _ := db.GetHost(ctx, t.db, record.Knot); host != nil {
85
+
knotUrl = host.URL()
86
+
} else {
87
+
t.logger.Warn("repo is from unknown knot")
88
+
if t.cfg.KnotUseSSL {
89
+
knotUrl = "https://" + knotUrl
90
+
} else {
91
+
knotUrl = "http://" + knotUrl
92
+
}
93
+
}
94
+
}
95
+
81
96
status := models.RepoStatePending
82
97
errMsg := ""
83
-
u, err := url.Parse("http://" + record.Knot) // parsing with fake scheme
98
+
u, err := url.Parse(knotUrl)
84
99
if err != nil {
85
100
status = models.RepoStateSuspended
86
101
errMsg = "failed to parse knot url"
···
94
109
Rkey: evt.Rkey,
95
110
Cid: evt.CID,
96
111
Name: record.Name,
97
-
KnotDomain: record.Knot,
112
+
KnotDomain: knotUrl,
98
113
State: status,
99
114
ErrorMsg: errMsg,
100
115
RetryAfter: 0, // clear retry info
+10
-1
knotmirror/xrpc/sync_requestCrawl.go
+10
-1
knotmirror/xrpc/sync_requestCrawl.go
···
61
61
}
62
62
record := out.Value.Val.(*tangled.Repo)
63
63
64
+
knotUrl := record.Knot
65
+
if !strings.Contains(record.Knot, "://") {
66
+
if noSSL {
67
+
knotUrl = "http://" + knotUrl
68
+
} else {
69
+
knotUrl = "https://" + knotUrl
70
+
}
71
+
}
72
+
64
73
repo := &models.Repo{
65
74
Did: owner.DID,
66
75
Rkey: repoAt.RecordKey(),
67
76
Cid: (*syntax.CID)(out.Cid),
68
77
Name: record.Name,
69
-
KnotDomain: record.Knot,
78
+
KnotDomain: knotUrl,
70
79
State: models.RepoStatePending,
71
80
ErrorMsg: "",
72
81
RetryAfter: 0,
+9
nix/modules/knot.nix
+9
nix/modules/knot.nix
···
115
115
'';
116
116
};
117
117
118
+
knotmirrors = mkOption {
119
+
type = types.listOf types.str;
120
+
default = [
121
+
"https://mirror.tangled.network"
122
+
];
123
+
description = "List of knotmirror hosts to request crawl";
124
+
};
125
+
118
126
server = {
119
127
listenAddr = mkOption {
120
128
type = types.str;
···
263
271
"KNOT_SERVER_PLC_URL=${cfg.server.plcUrl}"
264
272
"KNOT_SERVER_JETSTREAM_ENDPOINT=${cfg.server.jetstreamEndpoint}"
265
273
"KNOT_SERVER_OWNER=${cfg.server.owner}"
274
+
"KNOT_MIRRORS=${concatStringsSep "," cfg.knotmirrors}"
266
275
"KNOT_SERVER_LOG_DIDS=${
267
276
if cfg.server.logDids
268
277
then "true"
+5
-2
nix/vm.nix
+5
-2
nix/vm.nix
···
111
111
jetstreamEndpoint = jetstream;
112
112
listenAddr = "0.0.0.0:6444";
113
113
};
114
+
knotmirrors = [
115
+
"http://localhost:7000"
116
+
];
114
117
};
115
118
services.tangled.spindle = {
116
119
enable = true;
···
175
178
in {
176
179
knot = mkDataSyncScripts "/mnt/knot-data" config.services.tangled.knot.stateDir;
177
180
spindle = mkDataSyncScripts "/mnt/spindle-data" (builtins.dirOf config.services.tangled.spindle.server.dbPath);
178
-
knotmirror.after = ["postgresql.service"];
179
-
tap-knotmirror.after = ["postgresql.service"];
181
+
knotmirror.after = ["postgresql.target"];
182
+
tap-knotmirror.after = ["postgresql.target"];
180
183
};
181
184
})
182
185
];
History
2 rounds
0 comments
boltless.me
submitted
#1
1 commit
expand
collapse
nix,knotmirror: sync localhost knots
Signed-off-by: Seongmin Lee <git@boltless.me>
expand 0 comments
This pull has been deleted (possibly by jj abandon or jj squash)
boltless.me
submitted
#0
1 commit
expand
collapse
nix,knotmirror: sync localhost knots
Signed-off-by: Seongmin Lee <git@boltless.me>