Skip to content

Commit

Permalink
Remove unnecessary logging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jannickheisch committed Oct 27, 2023
1 parent 20075cb commit 1094e19
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,11 @@ class MainActivity : Activity() {

Log.d("IDENTITY", "is ${idStore.identity.toRef()} (${idStore.identity.verifyKey})")

//val dict = mutableMapOf<String,Any>()
//dict["test1"] = 1000
//dict["test2"] = 248
//Log.d("DICT TEST", "res: ${Bipf.bipf_loads(Bipf.encode(Bipf.mkDict(dict))!!)!!.get()}")

Log.d("INT TEST", "res: ${Bipf.bipf_loads(Bipf.encode(Bipf.mkInt(250))!!)!!.getInt()}")
val webView = findViewById<WebView>(R.id.webView)
wai = WebAppInterface(this, webView)
tinyIO = IO(this, wai)
tinyGoset._include_key(idStore.identity.verifyKey) // make sure our local key is in
tinyRepo.load()
//for (f in tinyRepo.listFeeds()) {
// tinyGoset._include_key(f)
//}
tinyGoset.adjust_state()
tinyDemux.arm_dmx(tinyGoset.goset_dmx, {buf:ByteArray, aux:ByteArray?, _ -> tinyGoset.rx(buf,aux)}, null)
tinyDemux.arm_dmx(tinyDemux.want_dmx!!, {buf:ByteArray, aux:ByteArray?, sender:String? -> tinyNode.incoming_want_request(buf,aux,sender)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Node(val context: MainActivity) {
}
var v= "CHNK vector=["
var credit = 3
Log.d("in_chnk", "outer")
for (e in vect.getBipfList()) {
val fNDX: Int
val fid: ByteArray
Expand Down Expand Up @@ -136,22 +135,6 @@ class Node(val context: MainActivity) {

Log.d("node", "beacon")

/*val l = arrayListOf<Any>()
val c = arrayListOf<Any>(1, "ok", 2)
l.add(c)
val b = Bipf.bipf_loads(Bipf.encode(Bipf.mk(l))!!)!!
val lst = b.getBipfList()[0].getBipfList()
val first = lst[0].get()
val sec = lst[1].get()
val third = lst[2].get()
Log.d("Test", "$first, $sec, $third")
return*/
val want_buf = context.tinyRepo.mk_want_vect()
if (want_buf != null)
context.tinyIO.enqueue(want_buf, context.tinyDemux.want_dmx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class State {

fun toWire(): ByteArray {
val wire = toDict()
Log.d("to_wire", "wire_maxpos: ${Bipf.bipf_loads(Bipf.encode(Bipf.mkDict(toDict()))!!)!!.get()}")
return Bipf.encode(Bipf.mkDict(toDict()))!!
}

Expand Down Expand Up @@ -91,7 +90,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
while (log.length() > state.max_pos) {
RandomAccessFile(log, "rwd").use { f ->
var pos = state.max_pos
Log.d("replica", "init pos: $pos")
f.seek(pos.toLong())
val pkt = ByteArray(TINYSSB_PKT_LEN)
f.read(pkt)
Expand Down Expand Up @@ -128,7 +126,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
fun persist_frontier(seq: Int, pos: Int, prev: ByteArray) {
state.max_seq = seq
state.max_pos = pos
Log.d("persist_frontier", "pos: $pos")
state.prev = prev
val f = fnt.startWrite()
f.write(state.toWire())
Expand Down Expand Up @@ -156,21 +153,18 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
fid
)
) {
Log.d("Replica", "ingest_entry: signature verify failed")
Log.e("Replica", "ingest_entry: signature verify failed")
return false
}
Log.d("Replica", "DEBUG REP")
var chunk_cnt = 0
if (pkt[7].toInt() == PKTTYPE_chain20) {
var (len, sz) = Bipf.varint_decode(pkt, DMX_LEN + 1, DMX_LEN + 4)
len -= 48 - 20 - sz
chunk_cnt = (len + 99) / 100
}
Log.d("Replica", "DEBUG REP 2")
var log_entry = pkt + ByteArray(chunk_cnt * TINYSSB_PKT_LEN)
log_entry += state.max_pos.toByteArray()
log.appendBytes(log_entry)
Log.d("Replica", "DEBUG REP 3, chunk_cnt: $chunk_cnt")
if (chunk_cnt > 0) {
val ptr = pkt.sliceArray(36 until 56)
state.pend_sc[seq] = Pending(0, chunk_cnt, ptr, state.max_pos + TINYSSB_PKT_LEN)
Expand All @@ -197,7 +191,7 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
}

fun ingest_chunk_pkt(pkt: ByteArray, seq: Int): Boolean {
Log.d("replica", "ingest_chunk-pkt")
Log.d("replica", "ingest_chunk_pkt")
if (pkt.size != TINYSSB_PKT_LEN) return false
val pend: Pending
var pos: Int
Expand All @@ -220,7 +214,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
state.pend_sc.remove(seq)
val content = read(seq)
val message_id = get_mid(seq)
Log.d("ingest_chnk", "sidechain complete, content: ${content?.toHex()}, mid: ${message_id?.toHex()}")
if (message_id != null && content != null) {
context.wai.sendTinyEventToFrontend(fid, seq, message_id, content)
}
Expand All @@ -229,7 +222,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
pend.rem--
pend.hptr = pkt.sliceArray(pkt.size - 20..pkt.lastIndex)
pend.pos = pos
Log.d("ingest_chnk", "arm new chnk dmx, cnr: ${pend.cnr}, rem: ${pend.rem}")
val chunk_fct = { chunk: ByteArray, fid: ByteArray?, seq: Int -> context.tinyNode.incoming_chunk(chunk,fid,seq) }
context.tinyDemux.arm_blb(pend.hptr, chunk_fct, fid, seq, pend.cnr)
}
Expand All @@ -242,7 +234,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
}

fun get_mid(seq: Int): ByteArray? {
Log.d("get_mid", "for seq: $seq")
if(seq < 1 || seq > state.max_seq)
return null
val pos = (seq - 1) * HASH_LEN
Expand Down Expand Up @@ -270,7 +261,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)

fun get_entry_pkt(seq: Int): ByteArray? {
try {
Log.d("get_entry", "seq: $seq, max: ${state.max_seq}")
if(seq < 1 || seq > state.max_seq)
return null
var pos = log.length()
Expand Down Expand Up @@ -340,28 +330,22 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
}

fun read(seq: Int): ByteArray? {
Log.d("read", "DEBUG, max seq: ${state.max_seq}, seq: $seq")
if (state.max_seq < seq || seq < 1)
return null
Log.d("read", "DEBUG1.1")
var pos = log.length()
Log.d("read", "DEBUG1.2, pos: $pos")
var cnt = state.max_seq - seq + 1
RandomAccessFile(log, "rwd").use { f ->
while (cnt > 0) {
f.seek(pos - 4)
pos = f.readInt().toLong()
cnt--
}
Log.d("read", "DEBUG2")
f.seek(pos)
val pkt = ByteArray(TINYSSB_PKT_LEN)
f.read(pkt)
Log.d("read", "DEBUG3")
if (pkt[7].toInt() == PKTTYPE_plain48)
return pkt.sliceArray(8 until 56)
if (pkt[7].toInt() == PKTTYPE_chain20) { //read whole sidechain
Log.d("read", "DEBUG4")
val (chain_len, sz) = Bipf.varint_decode(pkt, DMX_LEN + 1, DMX_LEN + 4)
var content = pkt.sliceArray(8 + sz until 36)
var blocks = (chain_len - content.size + 99) / 100
Expand Down Expand Up @@ -427,7 +411,6 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
val buf = content.sliceArray(content.size - 100 .. content.lastIndex) + ptr
chunks.add(buf)
ptr = buf.sha256().sliceArray(0 until HASH_LEN)
Log.d("write", "ptr: ${ptr.toHex()}, $d")
d++
content = content.sliceArray(0 .. content.lastIndex - 100)
}
Expand All @@ -450,13 +433,10 @@ class Replica(val context: MainActivity, val datapath: File, val fid: ByteArray)
chunks.add(0, wire)
var log_entry = chunks.reduce {acc, it -> acc + it}
log_entry += state.max_pos.toByteArray()
Log.d("size", "size before: ${log.length()}")
log.appendBytes(log_entry)
// save mid
mid.appendBytes((nam + wire).sha256().sliceArray(0 until HASH_LEN))
//Log.d("sizes", "sizes: dmx: ${dmx.size}, +1, payload: ${payload.size}, sign: ${signDetached(nam + msg, context.idStore.identity.signingKey!!).size}")
persist_frontier(seq, state.max_pos + log_entry.size, (nam + wire).sha256().sliceArray(0 until HASH_LEN))
Log.d("write", "new max pos: ${state.max_pos}")
context.wai.sendTinyEventToFrontend(fid, seq, (nam + wire).sha256().sliceArray(0 until HASH_LEN), c)
Log.d("replica", "write success, len: ${log_entry.size}")
return seq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class Repo(val context: MainActivity) {
for ((seq, p) in pending) {
val c = arrayListOf(ndx, seq, p.cnr)
lst.add(c)
Log.d("mk_chnk", "calc encoding len")
encoding_len += Bipf.encodingLength(c)
v += (if (v.length == 0) "[ " else " ") + "$ndx.$seq.${p.cnr}"
if (encoding_len > 100)
Expand All @@ -203,7 +202,6 @@ class Repo(val context: MainActivity) {
i++
if (encoding_len > 100)
break
Log.d("mk_chnk", "new feed")
chnk_offs = (chnk_offs + i + 1) % context.tinyGoset.keys.size

}
Expand Down

0 comments on commit 1094e19

Please sign in to comment.