Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DNS server #41

Merged
merged 7 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions v1/dns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import dns2 from 'dns2'
import { FastifyBaseLogger } from 'fastify'
import { SiteConfigStore } from '../config/sites.js'

export async function initDnsServer (port: number, store: SiteConfigStore, logger: FastifyBaseLogger): Promise<ReturnType<typeof dns2.createServer>> {
function protocolToMultiformat(link: string): string {
const [protocol, path] = link.split("://")
return `/${protocol}/${path}`
}

export async function initDnsServer(port: number, store: SiteConfigStore, logger: FastifyBaseLogger): Promise<ReturnType<typeof dns2.createServer>> {
const server = dns2.createServer({
udp: true,
handle: (request, send, rinfo) => {
Expand All @@ -13,14 +18,22 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge
const trimmedName = name.replace('_dnslink.', '')
store.get(trimmedName)
.then(({ links }) => {
// TODO(support http and hyper)
if (links.ipfs !== undefined) {
response.answers.push({
name,
type: dns2.Packet.TYPE.TXT,
class: dns2.Packet.CLASS.IN,
ttl: 60,
data: `dnslink=${links.ipfs.link}`
data: `dnslink=${protocolToMultiformat(links.ipfs.pubKey)}`
})
}
if (links.hyper !== undefined) {
response.answers.push({
name,
type: dns2.Packet.TYPE.TXT,
class: dns2.Packet.CLASS.IN,
ttl: 60,
data: `dnslink=${protocolToMultiformat(links.hyper.link)}`
jackyzha0 marked this conversation as resolved.
Show resolved Hide resolved
})
}
send(response)
Expand Down
2 changes: 1 addition & 1 deletion v1/protocols/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class IPFSProtocol implements Protocol<Static<typeof IPFSProtocolFields>>
const pubKey = `ipns://${publishKey}/`
return {
enabled: true,
link: pubKey,
link: `_dnslink.${id}`,
jackyzha0 marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Pass in gateway parameters in options (DP domain name?)
gateway: `https://gateway.ipfs.io/ipns/${publishKey}/`,
cid,
Expand Down