OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git commits / 85d590b

Revert swarm keypair change — broke all existing punch:// URLs
The identity keypair approach was wrong: it changed the server's Hyperswarm public key, breaking every client/peer configured with the old key. The real fix for stale federation refs needs to work at the federation sync level, not by changing the transport key. Kept: REFS debug logging in git-p2p-handler.js Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85d590b5ee2a67674528c12cc8518c713f3ba28d
by plankatron <fleeky@gmail.com> · 2026-04-07T03:43:44.000Z

Changed files (2) +2 -32

lib/p2p/discovery/topic-manager.js +2 -14
……@@ -214,7 +214,6 @@ export class TopicConnector {
214214 */
215215 async connect(serverKey, repoName) {
216216 const topic = ServerIdentity.deriveTopicFromKey(serverKey, repoName)
217 const expectedKey = Buffer.isBuffer(serverKey) ? serverKey : Buffer.from(serverKey, 'hex')
218217
219218 return new Promise((resolve, reject) => {
220219 const timeout = setTimeout(() => {
……@@ -223,24 +222,13 @@ export class TopicConnector {
223222
224223 this.swarm.join(topic, { server: false, client: true })
225224
226 const onConnection = (conn, peerInfo) => {
227 // Verify we connected to the expected server, not a federation peer
228 // or the local machine's own pear-git serving stale data.
229 if (!expectedKey.equals(peerInfo.publicKey)) {
230 console.error(`[TopicConnector] Wrong peer ${peerInfo.publicKey.toString('hex').slice(0, 8)}... (expected ${expectedKey.toString('hex').slice(0, 8)}...), retrying`)
231 conn.destroy()
232 return // wait for next connection
233 }
225 this.swarm.once('connection', (conn, peerInfo) => {
234226 clearTimeout(timeout)
235 this.swarm.off('connection', onConnection)
236227 resolve(conn)
237 }
238
239 this.swarm.on('connection', onConnection)
228 })
240229
241230 this.swarm.once('error', (err) => {
242231 clearTimeout(timeout)
243 this.swarm.off('connection', onConnection)
244232 reject(err)
245233 })
246234 })
pear-git-server.js +0 -18
……@@ -1155,24 +1155,6 @@ class PearGitServer {
11551155 console.log(' Keet identity: NOT SET \u2014 run `pgh identity setup`')
11561156 }
11571157
1158 // Recreate git swarm with server identity keypair so clients can verify
1159 // conn.remotePublicKey matches the expected server key from punch:// URLs.
1160 // Without this, any peer announcing the same topic (including federation
1161 // peers with stale data) could serve instead of the origin server.
1162 if (this.serverIdentity.publicKey && this.serverIdentity.secretKey) {
1163 const oldSwarm = this.swarm
1164 const swarmOpts = this._bootstrap ? { bootstrap: this._bootstrap } : {}
1165 swarmOpts.keyPair = {
1166 publicKey: this.serverIdentity.publicKey,
1167 secretKey: this.serverIdentity.secretKey
1168 }
1169 this.swarm = new Hyperswarm(swarmOpts)
1170 this.swarm.on('error', (err) => {
1171 console.error('[GitSwarm] Error:', err.message)
1172 })
1173 oldSwarm.destroy().catch(() => {})
1174 console.log(`[P2P] Git swarm using server identity key: ${this.serverIdentity.getPublicKeyHex().slice(0, 8)}...`)
1175 }
11761158
11771159 this.gitP2PHandler = new GitP2PHandler({
11781160 reposPath: this.repoRegistry.gitReposPath,