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

Adds liking videos and mostly functional profile page #141

Closed
wants to merge 157 commits into from
Closed
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
4be29f4
Minor issue in build files fixed
NikolayBlagoev Feb 22, 2023
192afe7
Added small like button
NikolayBlagoev Feb 26, 2023
9011ecf
Like button has attached function. Changed title to match tiktok form…
NikolayBlagoev Feb 28, 2023
0938d0a
Addet community
NikolayBlagoev Mar 1, 2023
a335cc0
Added community file
NikolayBlagoev Mar 1, 2023
51594da
Added like sending
NikolayBlagoev Mar 1, 2023
b5dd7a5
Update like to include liker (deserialize still needs fixing) + add c…
Mar 2, 2023
d952acf
fix serializer
Mar 2, 2023
d55dbd8
use trustchain blocks for likes
Mar 2, 2023
2232d3b
restore build files to original state
Mar 2, 2023
d2e0ba2
Added Like fields and removed delimitter
NikolayBlagoev Mar 3, 2023
7093df0
fix warning so the project compiles
Mar 4, 2023
2df433c
Merge branch '4-relay-messages-received' of github.com:NikolayBlagoev…
Mar 4, 2023
1a7b19f
public key added to broadcast like
ignjat-ignjat Mar 4, 2023
24cb796
working on fixing the broadcast like to a proper public key
ignjat-ignjat Mar 4, 2023
f8dac3e
add ui element for debugging to show numbers of peers
Mar 4, 2023
9b094ba
changed serviceid to unique value for test run
ignjat-ignjat Mar 5, 2023
ab26864
Added a tab bar
ivanstodorov Mar 6, 2023
f33bfcf
string to byte array for public key
ignjat-ignjat Mar 6, 2023
d13eeb5
sign and receive blocks
Mar 6, 2023
afc4e3a
split up creation of detokscommunity, add nsd overlay
Mar 6, 2023
e02fef1
Improved the looks of the like button
ivanstodorov Mar 7, 2023
9da7037
Added torrent creation
NikolayBlagoev Mar 8, 2023
8603e43
Still need to seed :/
NikolayBlagoev Mar 8, 2023
caaea0c
Trying to properly seed
NikolayBlagoev Mar 12, 2023
1ba47e9
esoteric kotlin
NikolayBlagoev Mar 12, 2023
1306434
actually add like to proposal blocks instead of empty map, add functi…
Mar 13, 2023
7e850d8
Merge pull request #14 from NikolayBlagoev/4-relay-messages-received
ignjat-ignjat Mar 13, 2023
03d6838
Finalised the skeleton of the profile page
ivanstodorov Mar 14, 2023
45a6417
CONTENT UPLOAD WORKS
NikolayBlagoev Mar 14, 2023
6da727f
Merge pull request #18 from NikolayBlagoev/4-relay-messages-received
NikolayBlagoev Mar 14, 2023
834e949
Fixed merge conflicts with master
ivanstodorov Mar 16, 2023
58fefea
list of liked videos per user function added
ignjat-ignjat Mar 17, 2023
4c4ad41
add some additional functions to couple to the front-end
Mar 17, 2023
cadbdb2
Merge branch 'profile-page' of github.com:NikolayBlagoev/trustchain-s…
Mar 17, 2023
9943ad2
change individual from byte array to string
ignjat-ignjat Mar 17, 2023
a17be7c
Return torrents in addition to videos in listoflikedvideosandtorrents…
ignjat-ignjat Mar 17, 2023
c5b544e
refactor + add some comments
Mar 17, 2023
d060af3
Merge branch 'profile-page' of github.com:NikolayBlagoev/trustchain-s…
Mar 17, 2023
5beeb66
mostly integrated UI with backend, but still some strange errors
Mar 17, 2023
81c4b78
Fix the Like class, creator_name changed to author
Mar 17, 2023
1611126
Merge pull request #15 from NikolayBlagoev/profile-page
WJehee Mar 17, 2023
28bd6f9
Minor UI/UX improvements
ivanstodorov Mar 17, 2023
e824554
Merge pull request #23 from NikolayBlagoev/profile-page
ivanstodorov Mar 17, 2023
35c13ae
Timestamp added in addition to sorting
ignjat-ignjat Mar 18, 2023
22234bd
Sorting changed to give the latest timestamp first
ignjat-ignjat Mar 18, 2023
3e0ac69
user can only like video if they didnt previously like it, preventing…
ignjat-ignjat Mar 20, 2023
60be8ff
Signature cannot be created if video has been liked by liker already
ignjat-ignjat Mar 20, 2023
2ff01da
Merge branch 'add-timestamp' of github.com:NikolayBlagoev/trustchain-…
ignjat-ignjat Mar 20, 2023
b4112ec
Torrent improvements
NikolayBlagoev Mar 21, 2023
28f73aa
Minor fixes
NikolayBlagoev Mar 21, 2023
3bf7e49
Removed need for ttorent
NikolayBlagoev Mar 21, 2023
48028b0
UF added
NikolayBlagoev Mar 22, 2023
5c483d1
Added a tab for video uploading
ivanstodorov Mar 22, 2023
6d96b87
fixed issue with file not found
NikolayBlagoev Mar 22, 2023
d9d68cc
Video link copying
NikolayBlagoev Mar 23, 2023
d1915f5
fix merge conflicts
Mar 27, 2023
b1deed1
fix imports, other issues and refactor
Mar 27, 2023
93fbfc4
merge communities
Mar 27, 2023
46e0aad
refactor / linter fixes
Mar 27, 2023
1171d64
fix most of the issues mentioned in the review
Mar 28, 2023
26b6a9f
fix last few issues
Mar 28, 2023
c411976
fix build file
Mar 28, 2023
4860176
local changes fixed
ignjat-ignjat Mar 28, 2023
0596d55
this will sort videos by most recent. To discuss with rest of the gro…
ignjat-ignjat Mar 29, 2023
8bbef13
two very different branches for torrenting, some changes done to try …
ignjat-ignjat Mar 29, 2023
288e458
locally merged new torrenting
ignjat-ignjat Mar 29, 2023
e9a5dc8
stop broadcasting in addMagne
ignjat-ignjat Mar 29, 2023
74d858f
initial recommender added
ignjat-ignjat Mar 30, 2023
21b120a
Fixed issues with content uploading - no longer requires a restart to…
ivanstodorov Mar 31, 2023
4b20644
Added automatic updates to the profile page (when switching between t…
ivanstodorov Mar 31, 2023
b10efb2
added torrent magnet to like, now we have magnet so as to download ne…
ignjat-ignjat Mar 31, 2023
a125420
fixed mustake in torrent manager class
ignjat-ignjat Mar 31, 2023
bc80edf
only sort torrentfiles list when downloading and not when deleting file
ignjat-ignjat Mar 31, 2023
fa4e010
add video to list of torrentfiles in addmagnet
ignjat-ignjat Mar 31, 2023
51dba63
Fixed version
NikolayBlagoev Mar 31, 2023
bf3e460
partial fix
ignjat-ignjat Mar 31, 2023
f1c23a2
Merge pull request #24 from NikolayBlagoev/add-timestamp
ignjat-ignjat Mar 31, 2023
78dd493
Revert "Add timestamp"
ignjat-ignjat Mar 31, 2023
28757c4
Merge pull request #32 from NikolayBlagoev/revert-24-add-timestamp
ignjat-ignjat Mar 31, 2023
e6f175f
Fixed merge conflicts
ivanstodorov Mar 31, 2023
0b38793
Merged with the latest version of add-timestamp
ivanstodorov Mar 31, 2023
26343b6
Fixed a bug with liking videos
ivanstodorov Mar 31, 2023
6f8f859
Merge remote-tracking branch 'origin/master' into torrenting
ivanstodorov Mar 31, 2023
bd1472e
Merge pull request #31 from NikolayBlagoev/torrenting
ignjat-ignjat Mar 31, 2023
1c304f7
Minor changes
ivanstodorov Mar 31, 2023
e067865
final minor change
Mar 31, 2023
2824fec
remove some warnings
Mar 31, 2023
33231b4
Changed the label and the icon for video uploading and made the icon red
ivanstodorov Apr 1, 2023
fdab8e2
fix TM
NikolayBlagoev Apr 3, 2023
c4bc014
see video on page
NikolayBlagoev Apr 3, 2023
d526917
removed unneeded code
Apr 4, 2023
e919077
Merge branch 'master' into Quality-of-life-improvements
Apr 6, 2023
3849738
Added automatic and manual updates to the home page and the profile page
ivanstodorov Apr 7, 2023
af8538d
Merge branch 'master' into ui-improvements
Apr 7, 2023
0f1632e
change magnet link in profile->liked videos to the name of the video
Apr 7, 2023
155a536
change magnet link to video name in liked list tab of profile page
Apr 7, 2023
1190b32
add gif
Apr 7, 2023
72d419b
Update README.md
WJehee Apr 7, 2023
0f69c22
Update README.md
WJehee Apr 7, 2023
b443228
recommender kind of works
ignjat-ignjat Apr 9, 2023
0031d10
recmmender now works up until all liked videos are watched, after tha…
ignjat-ignjat Apr 9, 2023
d933ee7
Crawler
NikolayBlagoev Apr 11, 2023
2ad1d14
Added a network page
ivanstodorov Apr 14, 2023
e0c61f5
Fixed merge conflicts
ivanstodorov Apr 14, 2023
76b7a7c
Added a dummy discovery fragment
ivanstodorov Apr 14, 2023
6383b25
Minor improvements
ivanstodorov Apr 14, 2023
e53c207
Fixed merge conflicts
ivanstodorov Apr 14, 2023
515b120
cleanup
ignjat-ignjat Apr 15, 2023
4d8e083
Merge branch 'ui-improvements' into recommender
ignjat-ignjat Apr 15, 2023
689857e
new branch pulled
ignjat-ignjat Apr 15, 2023
28ed697
Documentation
NikolayBlagoev Apr 17, 2023
1683e7a
Merge branch 'Quality-of-life-improvements' of github.com:NikolayBlag…
Apr 17, 2023
18760e9
Merge pull request #35 from NikolayBlagoev/crawl
WJehee Apr 17, 2023
bfd9df9
fix merge, move detoks/readme to main readme
Apr 17, 2023
d08c948
relative path for gif
WJehee Apr 17, 2023
0c88884
Update README.md
WJehee Apr 17, 2023
9b0b72c
recommender once again getting somewhere, bugs fixed
ignjat-ignjat Apr 17, 2023
49be3e1
Update README.md
NikolayBlagoev Apr 17, 2023
a31d5ba
custom tracker
NikolayBlagoev Apr 18, 2023
0ff272f
remove != null file
Apr 18, 2023
14d9160
Merge branch 'recommender' of github.com:NikolayBlagoev/trustchain-su…
Apr 18, 2023
23a8cc0
ALWAYS DOWNLOAD OWN VIDEO! THUS ALWAYS SEED!!
NikolayBlagoev Apr 18, 2023
5c2a373
Merge branch 'recommender' of github.com:NikolayBlagoev/trustchain-su…
NikolayBlagoev Apr 18, 2023
d32ed1c
logs
ignjat-ignjat Apr 18, 2023
1065e2a
remove condition in onBlockReceive
Apr 18, 2023
f258972
removed logging from other group
Apr 18, 2023
ccba0cc
get unique videos
ignjat-ignjat Apr 18, 2023
368df0b
log all unique videos in addmagnet
ignjat-ignjat Apr 18, 2023
05935f3
merged into dev
Apr 18, 2023
81b81b3
Merge branch 'recommender' of github.com:NikolayBlagoev/trustchain-su…
Apr 18, 2023
7317054
bunch of random changes, WIP
Apr 18, 2023
4ec3b9c
fix public key stuff hopefully
Apr 18, 2023
fa9e765
also change in index
Apr 18, 2023
29f7146
bug fixed with torrentmanager
ignjat-ignjat Apr 18, 2023
46d6078
fix ui public key stuff
Apr 19, 2023
0b2ec0d
change serviceId and fix bug
Apr 19, 2023
3762f62
more logging, remove gossiping
Apr 19, 2023
de47685
recommender used more
ignjat-ignjat Apr 19, 2023
25c1a2d
Update README.md
NikolayBlagoev Apr 19, 2023
4d11c00
return recommender to old state, only recommend unwatched videos
Apr 19, 2023
42c9290
Merge pull request #38 from NikolayBlagoev/recommender
WJehee Apr 19, 2023
f3a40cf
Bug fixes
ivanstodorov Apr 19, 2023
f12db6f
fix video list stuff
Apr 19, 2023
88c80ae
fix default torrent likes
Apr 19, 2023
2a5a286
Added discovery page
ivanstodorov Apr 19, 2023
b44ef2c
Fixed when video is considered watched
ivanstodorov Apr 19, 2023
7de57d6
fix merge
Apr 19, 2023
4feda72
Merge pull request #25 from NikolayBlagoev/Quality-of-life-improvements
WJehee Apr 19, 2023
53ccc8a
Update README.md
WJehee Apr 19, 2023
1b2fe1f
add screenshots for each page
WJehee Apr 19, 2023
58e1fc9
first run does not break the app
ignjat-ignjat Apr 19, 2023
f84e5c4
Merge branch 'dev' of github.com:NikolayBlagoev/trustchain-superapp i…
ignjat-ignjat Apr 19, 2023
1586a58
Minor bug fixes for the Network and Discovery pages
ivanstodorov Apr 20, 2023
0353bec
liking counter bugfix
Apr 20, 2023
2b644f2
change serviceID
Apr 20, 2023
accb20c
Merge pull request #42 from NikolayBlagoev/dev
WJehee May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,15 @@ class TrustChainApplication : Application() {
}

private fun createDeToksCommunity(): OverlayConfiguration<DeToksCommunity> {
val randomWalk = RandomWalk.Factory()
val settings = TrustChainSettings()
val driver = AndroidSqliteDriver(Database.Schema, this, "trustchain.db")
val store = TrustChainSQLiteStore(Database(driver))
return OverlayConfiguration(
DeToksCommunity.Factory(this),
listOf(randomWalk)
DeToksCommunity.Factory(this, settings, store),
listOf(
RandomWalk.Factory(),
NetworkServiceDiscovery.Factory(getSystemService()!!)
)
)
}

Expand Down
4 changes: 3 additions & 1 deletion detoks/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<application>
<activity
Expand Down
111 changes: 106 additions & 5 deletions detoks/src/main/java/nl/tudelft/trustchain/detoks/DeToksCommunity.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
package nl.tudelft.trustchain.detoks

import android.content.Context
import android.os.Build
import android.util.Log
import nl.tudelft.ipv8.Community
import androidx.annotation.RequiresApi
import nl.tudelft.ipv8.IPv4Address
import nl.tudelft.ipv8.Overlay
import nl.tudelft.ipv8.Peer
import nl.tudelft.ipv8.attestation.trustchain.*
import nl.tudelft.ipv8.attestation.trustchain.store.TrustChainStore
WJehee marked this conversation as resolved.
Show resolved Hide resolved
import nl.tudelft.ipv8.messaging.Packet
import nl.tudelft.ipv8.messaging.payload.IntroductionResponsePayload
import java.util.*

const val LIKE_BLOCK: String = "like_block"

class DeToksCommunity(private val context: Context) : Community() {
class DeToksCommunity(
private val context: Context, settings: TrustChainSettings,
database: TrustChainStore,
crawler: TrustChainCrawler = TrustChainCrawler()
) : TrustChainCommunity(settings, database, crawler) {

private val walletManager = WalletManager(context)
private val visitedPeers = mutableListOf<Peer>()

init {
messageHandlers[MESSAGE_TORRENT_ID] = ::onGossip
messageHandlers[MESSAGE_TRANSACTION_ID] = ::onTransactionMessage
registerBlockSigner(LIKE_BLOCK, object : BlockSigner {
override fun onSignatureRequest(block: TrustChainBlock) {
if(userLikedVideo(block.transaction["video"] as String,block.transaction["torrent"] as String, block.transaction["liker"] as String)) return
createAgreementBlock(block, block.transaction)
}
})
addListener(LIKE_BLOCK, object : BlockListener {
@RequiresApi(Build.VERSION_CODES.O)
override fun onBlockReceived(block: TrustChainBlock) {
Log.d("Detoks", "onBlockReceived: ${block.blockId} ${block.transaction}")
val video = block.transaction.get("video") as String
val torrent = block.transaction.get("torrent") as String
val magnet = block.transaction.get("torrentMagnet") as String
Log.d("Detoks", "Received like for $video, $torrent")
if (firstInstance(video, torrent)) TorrentManager.getInstance(context).addMagnet(magnet)

}
})
}

companion object {
Expand All @@ -26,7 +54,8 @@ class DeToksCommunity(private val context: Context) : Community() {
}

override val serviceId = "c86a7db45eb3563ae047639817baec4db2bc7c25"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still believe this should not be hardcoded but passed through some environment file


val discoveredAddressesContacted: MutableMap<IPv4Address, Date> = mutableMapOf()
val lastTrackerResponses = mutableMapOf<IPv4Address, Date>()

fun sendTokens(amount: Int, recipientMid: String) {
val senderWallet = walletManager.getOrCreateWallet(myPeer.mid)
Expand Down Expand Up @@ -99,11 +128,83 @@ class DeToksCommunity(private val context: Context) : Community() {
}
}

override fun onIntroductionResponse(peer: Peer, payload: IntroductionResponsePayload) {
super.onIntroductionResponse(peer, payload)

if (peer.address in DEFAULT_ADDRESSES) {
lastTrackerResponses[peer.address] = Date()
}
}

fun broadcastLike(vid: String, torrent: String, creator: String, magnet: String) {
if(userLikedVideo(vid,torrent,myPeer.publicKey.toString())) return
Log.d("DeToks", "Liking: $vid")
val timestamp = System.currentTimeMillis().toString()
val like = Like(myPeer.publicKey.toString(), vid, torrent, creator,timestamp, magnet)
createProposalBlock(LIKE_BLOCK, like.toMap(), myPeer.publicKey.keyToBin())
Log.d("DeToks", "$like")
}

fun getLikes(vid: String, torrent: String): List<TrustChainBlock> {
return database.getBlocksWithType(LIKE_BLOCK).filter {
it.transaction["video"] == vid && it.transaction["torrent"] == torrent
}
}

fun getBlocksByAuthor(author: String): List<TrustChainBlock> {
val authorsBlocks = database.getBlocksWithType(LIKE_BLOCK).filter {
it.transaction["author"] == author
}
if(authorsBlocks.isEmpty()) return authorsBlocks
return authorsBlocks.sortedWith(compareByDescending{(it.transaction["timestamp"] as String).toLong()})
}
fun getEarliestDate(vid: String, torrent: String):Long {
if(firstInstance(vid,torrent)) return Long.MAX_VALUE
return (getLikes(vid,torrent).sortedBy{(it.transaction["timestamp"] as String).toLong()}.get(0).transaction["timestamp"] as String).toLong()
}

fun userLikedVideo(vid: String, torrent: String, liker: String): Boolean {
return getLikes(vid, torrent).any { it.transaction["liker"] == liker }
}
fun firstInstance(vid: String, torrent: String): Boolean {
val exists = database.getBlocksWithType(LIKE_BLOCK).filter { it.transaction["video"] == vid && it.transaction["torrent"] == torrent }.size
if(exists == 0) return true
return false
}

fun getPostedVideos(author: String): List<Pair<String, Int>> {
// Create Key data class so we can group by two fields (torrent and video)
data class Key(val video: String, val torrent: String)
fun TrustChainBlock.toKey() = Key(transaction["video"] as String, transaction["torrent"] as String)
val likes = getBlocksByAuthor(author).groupBy { it.toKey() }
// no need to sort here as getblocksbyauthor already sorts
return likes.entries.map {
Pair(it.key.video, it.value.size)
}
}

fun listOfLikedVideosAndTorrents(person: String): List<Pair<String,String>> {
var iterato = database.getBlocksWithType(LIKE_BLOCK).filter {
it.transaction["liker"] == person
}
if(iterato.isEmpty()) return emptyList()
var iterator= iterato.sortedWith(compareByDescending{(it.transaction["timestamp"] as String).toLong()}).listIterator()
var likedVideos = ArrayList<Pair<String,String>>()
while(iterator.hasNext()) {
val block = iterator.next()
likedVideos.add(Pair(block.transaction.get("video") as String, block.transaction.get("torrentMagnet") as String))
}
return likedVideos;
}

class Factory(
private val context: Context
private val context: Context,
private val settings: TrustChainSettings,
private val database: TrustChainStore,
private val crawler: TrustChainCrawler = TrustChainCrawler()
) : Overlay.Factory<DeToksCommunity>(DeToksCommunity::class.java) {
override fun create(): DeToksCommunity {
return DeToksCommunity(context)
return DeToksCommunity(context, settings, database, crawler)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import androidx.preference.PreferenceManager
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.android.keyvault.AndroidCryptoProvider
import android.os.IBinder
import android.util.Log
import nl.tudelft.trustchain.common.BaseActivity
import nl.tudelft.ipv8.keyvault.PrivateKey
import nl.tudelft.ipv8.keyvault.defaultCryptoProvider
import nl.tudelft.ipv8.util.hexToBytes
import nl.tudelft.ipv8.util.toHex

class DeToksActivity : BaseActivity() {
override val navigationGraph = R.navigation.nav_graph_detoks
Expand All @@ -15,12 +23,19 @@ class DeToksActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val actionBar = supportActionBar
defaultCryptoProvider = AndroidCryptoProvider
actionBar!!.hide()

Intent(this, GossiperService::class.java).also { intent ->
startService(intent)
bindService(intent, gossipConnection, Context.BIND_AUTO_CREATE)
}

val community = IPv8Android.getInstance().getOverlay<DeToksCommunity>()!!
val peers = community.getPeers()
for (peer in peers) {
Log.d("DeToks", peer.mid)
}
}

private val gossipConnection = object : ServiceConnection {
Expand Down
53 changes: 53 additions & 0 deletions detoks/src/main/java/nl/tudelft/trustchain/detoks/Like.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package nl.tudelft.trustchain.detoks

import nl.tudelft.ipv8.messaging.*

class Like(val liker: String, val video: String, val torrent: String, val author: String, val timestamp: String, val torrentMagnet: String) : Serializable {
fun toMap(): Map<String, String> {
return mapOf(
"liker" to liker,
"video" to video,
"torrent" to torrent,
"author" to author,
"timestamp" to timestamp,
"torrentMagnet" to torrentMagnet
)
}
override fun serialize(): ByteArray {
return serializeVarLen(liker.toByteArray(Charsets.UTF_8)) +
serializeVarLen(video.toByteArray(Charsets.UTF_8)) +
serializeVarLen(torrent.toByteArray(Charsets.UTF_8)) +
serializeVarLen(author.toByteArray(Charsets.UTF_8)) +
serializeVarLen(timestamp.toByteArray(Charsets.UTF_8)) +
serializeVarLen(torrentMagnet.toByteArray(Charsets.UTF_8))
}

companion object Deserializer : Deserializable<Like> {
override fun deserialize(buffer: ByteArray, offset: Int): Pair<Like, Int> {
var localOffset = 0
val (liker, likerSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += likerSize
val (video, videoSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += videoSize
val (torrent, torrentSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += torrentSize
val (creator_name, cretorSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += cretorSize
val (timestamp, timestampSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += timestampSize
val (torrentMagnet, torrentMagnetSize) = deserializeVarLen(buffer, offset + localOffset)
localOffset += torrentMagnetSize
return Pair(
Like(
liker.toString(Charsets.UTF_8),
video.toString(Charsets.UTF_8),
torrent.toString(Charsets.UTF_8),
creator_name.toString(Charsets.UTF_8),
timestamp.toString(Charsets.UTF_8),
torrentMagnet.toString(Charsets.UTF_8)
),
localOffset
)
}
}
}
Loading