Skip to content

Commit

Permalink
added own ip & pk to debug dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepMulder committed Mar 18, 2024
1 parent a11a4fe commit f697bdf
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package nl.tudelft.trustchain.currencyii.ui.bitcoin


import android.os.Bundle
import android.util.Log
import android.text.format.Formatter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.attestation.trustchain.TrustChainBlock
import nl.tudelft.ipv8.util.toHex
import nl.tudelft.trustchain.currencyii.CoinCommunity
import nl.tudelft.trustchain.currencyii.R
import nl.tudelft.trustchain.currencyii.coin.BitcoinNetworkOptions
import nl.tudelft.trustchain.currencyii.coin.MAIN_NET_WALLET_NAME
import nl.tudelft.trustchain.currencyii.coin.REG_TEST_WALLET_NAME
import nl.tudelft.trustchain.currencyii.coin.TEST_NET_WALLET_NAME
import nl.tudelft.trustchain.currencyii.coin.WalletManagerAndroid
import nl.tudelft.trustchain.currencyii.coin.WalletManagerConfiguration
import nl.tudelft.trustchain.currencyii.databinding.FragmentDebugDashboardBinding
import nl.tudelft.trustchain.currencyii.databinding.FragmentMyDaosBinding
import nl.tudelft.trustchain.currencyii.sharedWallet.SWJoinBlockTransactionData
import nl.tudelft.trustchain.currencyii.ui.BaseFragment
import java.io.File
import java.net.InetAddress
import java.net.NetworkInterface
import java.util.Collections
import java.util.Locale


/**
* A simple [Fragment] subclass.
Expand All @@ -39,6 +30,9 @@ class DebugDashboardFragment : BaseFragment(R.layout.fragment_debug_dashboard) {
private val binding get() = _binding!!
private var adapter: PeerListAdapter? = null
private var isFetching: Boolean = false
private var ipv8 = IPv8Android.getInstance()




@Deprecated("Deprecated in Java")
Expand All @@ -50,7 +44,7 @@ class DebugDashboardFragment : BaseFragment(R.layout.fragment_debug_dashboard) {
}

private fun initListeners() {
binding.joinDaoRefreshSwiper.setOnRefreshListener {
binding.connectedPeersRefreshSwiper.setOnRefreshListener {
this.refresh()
}
}
Expand All @@ -65,14 +59,14 @@ class DebugDashboardFragment : BaseFragment(R.layout.fragment_debug_dashboard) {
private fun enableRefresher() {
try {
this.isFetching = true
binding.joinDaoRefreshSwiper.isRefreshing = true
binding.connectedPeersRefreshSwiper.isRefreshing = true
} catch (_: Exception) {
}
}

private fun disableRefresher() {
try {
binding.joinDaoRefreshSwiper.isRefreshing = false
binding.connectedPeersRefreshSwiper.isRefreshing = false
} catch (_: Exception) {
}
}
Expand All @@ -85,6 +79,8 @@ class DebugDashboardFragment : BaseFragment(R.layout.fragment_debug_dashboard) {
// Inflate the layout for this fragment
showNavBar()
_binding = FragmentDebugDashboardBinding.inflate(inflater, container, false)


return binding.root
}

Expand All @@ -98,23 +94,48 @@ class DebugDashboardFragment : BaseFragment(R.layout.fragment_debug_dashboard) {
}

private fun getPeersAndUpdateUI() {
val peers = IPv8Android.getInstance().getOverlay<CoinCommunity>()!!.getPeers();
val peers = ipv8.getOverlay<CoinCommunity>()!!.getPeers();


adapter = PeerListAdapter(
this@DebugDashboardFragment,
peers)

binding.listView.adapter = adapter
binding.listView.adapter = adapter;
// ipv8.myPeer.address is empty so have to get IP with method below
binding.myIpv4.text = getMyIPv4Address();
binding.myPublicKey.text = ipv8.myPeer.publicKey.toString()


disableRefresher()
}






companion object {
@JvmStatic
fun newInstance() = DebugDashboardFragment()
}

fun getMyIPv4Address(): String? {
try {
val interfaces: List<NetworkInterface> =
Collections.list(NetworkInterface.getNetworkInterfaces())
for (intf in interfaces) {
val addrs: List<InetAddress> = Collections.list(intf.inetAddresses)
for (addr in addrs) {
if (!addr.isLoopbackAddress) {
val sAddr = addr.hostAddress
val isIPv4 = sAddr.indexOf(':') < 0
if (isIPv4) {
val x = sAddr
val ip = Formatter.formatIpAddress(sAddr.hashCode());
return ip
}
}
}
}
} catch (ignored: java.lang.Exception) {
return "No IP found"
}
return ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ class PeerListAdapter(

val ipv4 = binding.ipv4
var last_request = binding.lastRequest;
var last_response = binding.lastResponse
var last_response = binding.lastResponse;
var public_key = binding.publicKey



ipv4.text = peer.address.ip
last_request.text = peer.lastRequest?.let { formatter.format(it) };
last_response.text = peer.lastResponse?.let { formatter.format(it) };
public_key.text = peer.publicKey.toString();


return view
Expand Down
89 changes: 76 additions & 13 deletions currencyii/src/main/res/layout/fragment_debug_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,86 @@
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Connected peers:" />
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/join_dao_refresh_swiper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="My IPv4:" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="My Public key: " />



</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/my_ipv4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="text" />

<ListView
android:id="@+id/list_view"
<TextView
android:id="@+id/my_public_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="text" />

</LinearLayout>

</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Connected peers:" />

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/connected_peers_refresh_swiper"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>



</LinearLayout>




</LinearLayout>
Expand Down
11 changes: 11 additions & 0 deletions currencyii/src/main/res/layout/peer_row_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="Last request:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="Public key: " />



Expand Down Expand Up @@ -67,6 +72,12 @@
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="text" />
<TextView
android:id="@+id/public_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="text" />



Expand Down

0 comments on commit f697bdf

Please sign in to comment.