diff --git a/app/src/main/java/com/futo/polycentric/core/ProcessHandle.kt b/app/src/main/java/com/futo/polycentric/core/ProcessHandle.kt index 380697532d818e57c8758f60928aae79286267b6..82b4b7b00399cee0cf1f241e6e6fdb63f5a1bac2 100644 --- a/app/src/main/java/com/futo/polycentric/core/ProcessHandle.kt +++ b/app/src/main/java/com/futo/polycentric/core/ProcessHandle.kt @@ -175,9 +175,7 @@ class ProcessHandle constructor( val bytesToUpload = content.sliceArray(IntRange(i, end)) val pointer = publish( ContentType.BLOB_SECTION.value, - Protocol.BlobSection.newBuilder() - .setContent(ByteString.copyFrom(bytesToUpload)) - .build().toByteArray(), + bytesToUpload, null, null, mutableListOf() @@ -227,9 +225,9 @@ class ProcessHandle constructor( for (section in imageManifest.sectionsList) { val sectionEvents = blobEvents.filter { it.event.logicalClock >= section.low && it.event.logicalClock <= section.high }.sortedBy { it.event.logicalClock } sectionEvents.forEach { - val blobSection = Protocol.BlobSection.parseFrom(it.event.content) - val size = blobSection.content.size() - blobSection.content.copyTo(totalArray, offset) + val blobSection = it.event.content + val size = blobSection.size + blobSection.copyInto(totalArray, offset) offset += size } } diff --git a/app/src/main/java/com/futo/polycentric/core/Utility.kt b/app/src/main/java/com/futo/polycentric/core/Utility.kt index e9895b37485bde78d6e4aa49a3fd01897af558e5..34d6b60d9f808a79da69ccd78b9a81a13a5153e5 100644 --- a/app/src/main/java/com/futo/polycentric/core/Utility.kt +++ b/app/src/main/java/com/futo/polycentric/core/Utility.kt @@ -2,6 +2,7 @@ package com.futo.polycentric.core import android.util.Base64 import com.futo.polycentric.core.serializers.ClaimSerializer +import com.google.protobuf.ByteString import kotlinx.serialization.Serializable import userpackage.Protocol import userpackage.Protocol.Claim @@ -129,4 +130,21 @@ fun combineHashCodes(hashCodes: List<Int?>): Int { result = 31 * result + (hashCode ?: 0) } return result +} + +fun Protocol.ImageManifest.toURLInfoSystemLinkUrl(system: Protocol.PublicKey, process: Protocol.Process, servers: Iterable<String>): String { + val urlInfo = Protocol.URLInfo.newBuilder() + .setUrlType(4) + .setBody(Protocol.URLInfoDataLink.newBuilder() + .setSystem(system) + .setProcess(process) + .addAllServers(servers) + .setByteCount(byteCount) + .addAllSections(sectionsList) + .setMime(mime) + .build() + .toByteString()) + .build(); + + return "polycentric://" + urlInfo.toByteArray().toBase64Url() } \ No newline at end of file diff --git a/app/src/main/proto/com/futo/polycentric/protos/protocol.proto b/app/src/main/proto/com/futo/polycentric/protos/protocol.proto index 214825d7e127b86c4ac1e268f9d927048292c500..85b05499f1de75b604e4366834a26cb91033384d 100644 --- a/app/src/main/proto/com/futo/polycentric/protos/protocol.proto +++ b/app/src/main/proto/com/futo/polycentric/protos/protocol.proto @@ -48,15 +48,6 @@ message Server { string server = 1; } -message BlobMeta { - uint64 section_count = 1; - string mime = 2; -} - -message BlobSection { - bytes content = 1; -} - message ImageManifest { string mime = 1; uint64 width = 2; @@ -263,6 +254,7 @@ message URLInfo { // url_type 1 = URLInfoSystemLink // url_type 2 = URLInfoEventLink // url_type 3 = ExportBundle + // url_type 4 = URLInfoDataLink uint64 url_type = 1; bytes body = 2; } @@ -278,3 +270,12 @@ message URLInfoEventLink { uint64 logical_clock = 3; repeated string servers = 4; } + +message URLInfoDataLink { + PublicKey system = 1; + Process process = 2; + repeated string servers = 3; + uint64 byte_count = 4; + repeated Range sections = 5; + optional string mime = 6; +}