use host as authority and link type as root of path

dbus-notify
Zlatin Balevsky 2022-08-04 15:58:58 +01:00
parent 6dfddacb8d
commit 25d355026b
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 21 additions and 24 deletions

View File

@ -33,10 +33,6 @@ class FileMuLink extends MuLink {
throw new InvalidMuLinkException("invalid size $fileSize")
if (pieceSizePow2 < FileHasher.MIN_PIECE_SIZE_POW2 || pieceSizePow2 > FileHasher.MAX_PIECE_SIZE_POW2)
throw new InvalidMuLinkException("invalid piece size $pieceSizePow2")
Path path = Path.of(name)
if (path.getNameCount() != 1)
throw new InvalidMuLinkException("name path count ${path.getNameCount()}")
}
FileMuLink(SharedFile sharedFile, Persona me, SigningPrivateKey spk) {

View File

@ -8,7 +8,8 @@ import net.i2p.data.Base64
import net.i2p.data.Signature
import net.i2p.data.SigningPublicKey
import java.nio.charset.StandardCharsets
import java.nio.charset.StandardCharsets
import java.nio.file.Path
abstract class MuLink {
@ -58,7 +59,6 @@ abstract class MuLink {
def query = [:]
query.name = URLEncoder.encode(name, StandardCharsets.UTF_8)
query.sig = Base64.encode(sig)
query.type = linkType.name()
addQueryElements(query)
def kvs = []
@ -68,12 +68,10 @@ abstract class MuLink {
String queryStr = kvs.join("&")
URI uri = new URI(SCHEME,
Base64.encode(infoHash.getRoot()),
host.toBase64(),
PORT,
"/",
queryStr,
null)
host.toBase64(),
"/${linkType.name()}/" + Base64.encode(infoHash.getRoot()),
queryStr,
null)
uri.toASCIIString()
}
@ -84,14 +82,21 @@ abstract class MuLink {
URI uri = new URI(url)
if (uri.getScheme() != SCHEME)
throw new InvalidMuLinkException("Unsupported scheme ${uri.getScheme()}")
if (uri.getUserInfo() == null)
throw new InvalidMuLinkException("no infohash")
InfoHash ih = new InfoHash(Base64.decode(uri.getUserInfo()))
if (uri.getHost() == null)
if (uri.getAuthority() == null)
throw new InvalidMuLinkException("no persona")
Persona p = new Persona(new ByteArrayInputStream(Base64.decode(uri.getHost())))
Persona p = new Persona(new ByteArrayInputStream(Base64.decode(uri.getAuthority())))
if (uri.getPath() == null)
throw new InvalidMuLinkException("no path")
String [] pathElements = uri.getPath().split("/")
if (pathElements.length < 3)
throw new InvalidMuLinkException("path elements ${pathElements.length}")
LinkType linkType = LinkType.valueOf(pathElements[1])
InfoHash ih = new InfoHash(Base64.decode(pathElements[2]))
Map<String,String> query = parseQuery(uri.getQuery())
@ -105,10 +110,6 @@ abstract class MuLink {
if (sigBytes.length != Constants.SIG_TYPE.getSigLen())
throw new InvalidMuLinkException("invalid sig key")
if (query.type == null)
throw new InvalidMuLinkException("type missing")
LinkType linkType = LinkType.valueOf(query.type)
if (linkType == LinkType.FILE)
return new FileMuLink(p, ih, n, sigBytes, query)
throw new InvalidMuLinkException("unknown type $linkType")
@ -132,7 +133,7 @@ abstract class MuLink {
if (rv.containsKey(k))
throw new InvalidMuLinkException("duplicate key $k")
rv.k = v
rv[k] = v
}
rv
}