mirror of
https://github.com/DanielPollithy/flashwifi.git
synced 2025-10-16 11:45:32 +00:00
start to include flash channel (with error to debug)
This commit is contained in:
parent
1f4de84689
commit
a1698cb4fb
@ -21,6 +21,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -79,6 +80,16 @@ public class HotspotFragment extends Fragment {
|
|||||||
final View activity_view = getActivity().findViewById(R.id.drawer_layout);
|
final View activity_view = getActivity().findViewById(R.id.drawer_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String what = intent.getStringExtra("what");
|
||||||
|
String message = intent.getStringExtra("message");
|
||||||
|
|
||||||
|
if (message != null && message.equals("error")) {
|
||||||
|
String snd_message = intent.getStringExtra("snd_message");
|
||||||
|
Toast.makeText(getContext(), snd_message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -141,21 +141,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initUi() {
|
private void initUi() {
|
||||||
/*final Switch switch_ = (Switch) findViewById(R.id.wifiSwitch);
|
|
||||||
switch_.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
if (isChecked) {
|
|
||||||
if (!mBound) {
|
|
||||||
switch_.setChecked(false);
|
|
||||||
Toast.makeText(getApplicationContext(), "Wifi Broadcast not bound", Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
mService.enableService();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mService.disableService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readFile(String name) {
|
private String readFile(String name) {
|
||||||
|
|||||||
@ -114,6 +114,11 @@ public class SearchFragment extends Fragment {
|
|||||||
if (message != null && message.equals("error")) {
|
if (message != null && message.equals("error")) {
|
||||||
String snd_message = intent.getStringExtra("snd_message");
|
String snd_message = intent.getStringExtra("snd_message");
|
||||||
Snackbar.make(view, snd_message, Snackbar.LENGTH_LONG).setAction("Action", null).show();
|
Snackbar.make(view, snd_message, Snackbar.LENGTH_LONG).setAction("Action", null).show();
|
||||||
|
if (getmService() != null) {
|
||||||
|
getmService().setBusy(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
PeerStore.getInstance().clear();
|
||||||
updateList();
|
updateList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,9 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.flashwifi.wifip2p.datastore.PeerInformation;
|
import com.flashwifi.wifip2p.datastore.PeerInformation;
|
||||||
import com.flashwifi.wifip2p.datastore.PeerStore;
|
import com.flashwifi.wifip2p.datastore.PeerStore;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.*;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.FlashChannelHelper;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.Model.Digest;
|
||||||
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
|
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
|
||||||
import com.flashwifi.wifip2p.protocol.BillMessage;
|
import com.flashwifi.wifip2p.protocol.BillMessage;
|
||||||
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
|
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
|
||||||
@ -28,7 +31,9 @@ import java.net.NetworkInterface;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
|
||||||
@ -44,6 +49,8 @@ public class BillingClient {
|
|||||||
private static final String TAG = "BillingClient";
|
private static final String TAG = "BillingClient";
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final String mac;
|
private final String mac;
|
||||||
|
private final String seed;
|
||||||
|
private final int seedindex;
|
||||||
private State state = State.NOT_PAIRED;
|
private State state = State.NOT_PAIRED;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private SocketWrapper socketWrapper;
|
private SocketWrapper socketWrapper;
|
||||||
@ -55,6 +62,8 @@ public class BillingClient {
|
|||||||
private BillingOpenChannelAnswer billingOpenChannelAnswer;
|
private BillingOpenChannelAnswer billingOpenChannelAnswer;
|
||||||
private BillMessage[] billMessages;
|
private BillMessage[] billMessages;
|
||||||
|
|
||||||
|
FlashChannelHelper one;
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
private void sendUpdateUIBroadcastWithMessage(String message){
|
private void sendUpdateUIBroadcastWithMessage(String message){
|
||||||
@ -64,10 +73,12 @@ public class BillingClient {
|
|||||||
context.sendBroadcast(local);
|
context.sendBroadcast(local);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BillingClient(String mac, Context context){
|
public BillingClient(String mac, Context context, String seed, int seedindex){
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.mac = mac;
|
this.mac = mac;
|
||||||
gson = new GsonBuilder().create();
|
gson = new GsonBuilder().create();
|
||||||
|
this.seed = seed;
|
||||||
|
this.seedindex = seedindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,25 +125,61 @@ public class BillingClient {
|
|||||||
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
|
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
|
||||||
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
|
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
|
||||||
|
|
||||||
// ToDo: replace magic number with setting
|
|
||||||
int totalMegabytes = 100;
|
|
||||||
int treeDepth = 8;
|
|
||||||
String[] digests = new String[]{"1234", "2345", "3456"};
|
|
||||||
int timeoutMinutesClient = 20 * 60 * 1000;
|
|
||||||
|
|
||||||
int iotaPerMegabyte = offer.getIotaPerMegabyte();
|
int iotaPerMegabyte = offer.getIotaPerMegabyte();
|
||||||
String clientRefundAddress = finalization.getClientRefundAddress();
|
//String clientRefundAddress = finalization.getClientRefundAddress();
|
||||||
int totalMinutes = answer.getDuranceInMinutes();
|
int totalMinutes = answer.getDuranceInMinutes();
|
||||||
|
|
||||||
billingOpenChannel = new BillingOpenChannel(totalMegabytes, iotaPerMegabyte, clientRefundAddress, treeDepth, digests, timeoutMinutesClient, totalMinutes);
|
// the deposit of one party
|
||||||
|
int iotaDeposit = Accountant.getInstance().getTotalIotaDeposit();
|
||||||
|
int totalMegabytes = totalMinutes; // assumption 1MB per minute
|
||||||
|
int treeDepth = com.flashwifi.wifip2p.iotaFlashWrapper.FlashChannelHelper.getRequiredDepth(10);
|
||||||
|
|
||||||
|
one = FlashChannelHelper.getInstance();
|
||||||
|
double[] deposits = new double[]{iotaDeposit, iotaDeposit};
|
||||||
|
// client is always userIndex==0
|
||||||
|
// ToDo: remove mocked data
|
||||||
|
String seed = "RDNUSLPNOQUGDIZVOINTYRIRRIJMLODOC9ZTQU9KQSCDXPVSBILXUE9AHEOA9MNYZWNSECAVPQ9QSAHCN";
|
||||||
|
one.setupUser(0, seed, seedindex, 1);
|
||||||
|
one.setupFlash(deposits, treeDepth);
|
||||||
|
|
||||||
|
// The addresses must be exchanged over the network.
|
||||||
|
// When done setup the settlementAddresses.
|
||||||
|
ArrayList<String> settlementAddresses = new ArrayList<>();
|
||||||
|
settlementAddresses.add(answer.getClientSettlementAddress());
|
||||||
|
settlementAddresses.add(finalization.getHotspotSettlementAddress());
|
||||||
|
|
||||||
|
// Set the addresses
|
||||||
|
one.setupSettlementAddresses(settlementAddresses);
|
||||||
|
|
||||||
|
List<Digest> initialDigestsOne = one.initialChannelDigests();
|
||||||
|
int timeoutMinutesClient = 20 * 60 * 1000;
|
||||||
|
|
||||||
|
billingOpenChannel = new BillingOpenChannel(totalMegabytes, iotaPerMegabyte, treeDepth, initialDigestsOne, timeoutMinutesClient, totalMinutes);
|
||||||
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
|
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
|
||||||
String billingOpenChannelString = gson.toJson(billingOpenChannel);
|
String billingOpenChannelString = gson.toJson(billingOpenChannel);
|
||||||
socketWrapper.sendLine(billingOpenChannelString);
|
socketWrapper.sendLine(billingOpenChannelString);
|
||||||
|
|
||||||
// receive the hotspot details for the flash channel
|
// receive the hotspot details for the flash channel
|
||||||
String billingOpenChannelAnswerString = socketWrapper.getLineThrowing();
|
String billingOpenChannelAnswerString = socketWrapper.getLineThrowing();
|
||||||
billingOpenChannelAnswer = gson.fromJson(billingOpenChannelAnswerString, BillingOpenChannelAnswer.class);
|
billingOpenChannelAnswer = gson.fromJson(billingOpenChannelAnswerString, BillingOpenChannelAnswer.class);
|
||||||
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
|
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
|
||||||
|
|
||||||
// now create the flash channel on our side
|
// now create the flash channel on our side
|
||||||
|
List<List<Digest>> digestPairs = new ArrayList<>();
|
||||||
|
digestPairs.add(initialDigestsOne);
|
||||||
|
digestPairs.add(billingOpenChannelAnswer.getHotspotDigests());
|
||||||
|
|
||||||
|
one.setupChannelWithDigests(digestPairs);
|
||||||
|
|
||||||
|
Log.d("[ROOT ADDR]", one.getRootAddressWithChecksum());
|
||||||
|
|
||||||
|
// assert that the root address of both parties are the same
|
||||||
|
if (one.getRootAddressWithChecksum().equals(billingOpenChannelAnswer.getChannelRootAddress())) {
|
||||||
|
Log.d(TAG, "start: HOOOORAY! The multisig addresses match!");
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "start: :( :( :( :( :( :( A day to cry. the multisig addresses don't match");
|
||||||
|
}
|
||||||
|
|
||||||
Accountant.getInstance().start(billingOpenChannel.getTotalMegabytes(), billingOpenChannel.getTimeoutMinutesClient(), billingOpenChannel.getTotalMinutes(), billingOpenChannelAnswer.getClientDepositIota(),
|
Accountant.getInstance().start(billingOpenChannel.getTotalMegabytes(), billingOpenChannel.getTimeoutMinutesClient(), billingOpenChannel.getTotalMinutes(), billingOpenChannelAnswer.getClientDepositIota(),
|
||||||
billingOpenChannel.getIotaPerMegabyte());
|
billingOpenChannel.getIotaPerMegabyte());
|
||||||
sendUpdateUIBroadcastWithMessage("Channel established");
|
sendUpdateUIBroadcastWithMessage("Channel established");
|
||||||
|
|||||||
@ -12,6 +12,9 @@ import android.text.format.Formatter;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.flashwifi.wifip2p.datastore.PeerStore;
|
import com.flashwifi.wifip2p.datastore.PeerStore;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.*;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.FlashChannelHelper;
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.Model.Digest;
|
||||||
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
|
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
|
||||||
import com.flashwifi.wifip2p.protocol.BillMessage;
|
import com.flashwifi.wifip2p.protocol.BillMessage;
|
||||||
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
|
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
|
||||||
@ -32,7 +35,9 @@ import java.net.ServerSocket;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
|
||||||
@ -49,15 +54,17 @@ public class BillingServer {
|
|||||||
private static final String TAG = "BillingServer";
|
private static final String TAG = "BillingServer";
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final String mac;
|
private final String mac;
|
||||||
private final String hotspotRefundAddress;
|
|
||||||
private final String channelRootAddress;
|
private final String channelRootAddress;
|
||||||
private final String[] digests;
|
private final String seed;
|
||||||
|
private final int seedindex;
|
||||||
private State state = State.NOT_PAIRED;
|
private State state = State.NOT_PAIRED;
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private SocketWrapper socketWrapper;
|
private SocketWrapper socketWrapper;
|
||||||
private int PORT = 9199;
|
private int PORT = 9199;
|
||||||
private static final int serverTimeoutMillis = 2 * 60 * 1000;
|
private static final int serverTimeoutMillis = 2 * 60 * 1000;
|
||||||
|
FlashChannelHelper two;
|
||||||
|
List<Digest> initialDigestsTwo;
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
NetworkStatsManager networkStatsManager;
|
NetworkStatsManager networkStatsManager;
|
||||||
@ -69,9 +76,11 @@ public class BillingServer {
|
|||||||
context.sendBroadcast(local);
|
context.sendBroadcast(local);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BillingServer(String mac, Context context){
|
public BillingServer(String mac, Context context, String seed, int seedindex){
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.mac = mac;
|
this.mac = mac;
|
||||||
|
this.seed = seed;
|
||||||
|
this.seedindex = seedindex;
|
||||||
|
|
||||||
Log.d(TAG, "BillingServer: MAC of other part: " + mac);
|
Log.d(TAG, "BillingServer: MAC of other part: " + mac);
|
||||||
|
|
||||||
@ -80,22 +89,40 @@ public class BillingServer {
|
|||||||
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
|
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
|
||||||
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
|
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
|
||||||
// get the necessary values
|
// get the necessary values
|
||||||
// ToDo: replace magic number with setting
|
|
||||||
int totalMegabytes = 100;
|
|
||||||
int treeDepth = 8;
|
|
||||||
this.digests = new String[]{"1234", "2345", "3456"};
|
|
||||||
int timeoutMinutesServer = 2 * 60 * 1000;
|
|
||||||
|
|
||||||
this.hotspotRefundAddress = finalization.getHotspotRefundAddress();
|
|
||||||
this.channelRootAddress = finalization.getDepositAddressFlashChannel();
|
|
||||||
|
|
||||||
|
|
||||||
int iotaPerMegabyte = offer.getIotaPerMegabyte();
|
int iotaPerMegabyte = offer.getIotaPerMegabyte();
|
||||||
int iotaDepositClient = totalMegabytes * iotaPerMegabyte;
|
//String clientRefundAddress = finalization.getClientRefundAddress();
|
||||||
String clientRefundAddress = finalization.getClientRefundAddress();
|
|
||||||
int totalMinutes = answer.getDuranceInMinutes();
|
int totalMinutes = answer.getDuranceInMinutes();
|
||||||
|
|
||||||
Accountant.getInstance().start(totalMegabytes, timeoutMinutesServer, totalMinutes, iotaDepositClient, iotaPerMegabyte);
|
// the deposit of one party
|
||||||
|
int iotaDeposit = finalization.getDepositServerFlashChannelInIota();
|
||||||
|
int totalMegabytes = totalMinutes; // assumption 1MB per minute
|
||||||
|
int treeDepth = com.flashwifi.wifip2p.iotaFlashWrapper.FlashChannelHelper.getRequiredDepth(10);
|
||||||
|
|
||||||
|
|
||||||
|
two = com.flashwifi.wifip2p.iotaFlashWrapper.FlashChannelHelper.getInstance();
|
||||||
|
double[] deposits = new double[]{iotaDeposit, iotaDeposit};
|
||||||
|
// client is always userIndex==1
|
||||||
|
// ToDo: remove mock data
|
||||||
|
seed = "IUQDBHFDXK9EHKC9VUHCUXDLICLRANNDHYRMDYFCGSZMROWCZBLBNRKXWBSWZYDMLLHIHMP9ZPOPIFUSW";
|
||||||
|
two.setupUser(1, seed, seedindex, 1);
|
||||||
|
two.setupFlash(deposits, treeDepth);
|
||||||
|
|
||||||
|
// The addresses must be exchanged over the network.
|
||||||
|
// When done setup the settlementAddresses.
|
||||||
|
ArrayList<String> settlementAddresses = new ArrayList<>();
|
||||||
|
settlementAddresses.add(answer.getClientSettlementAddress());
|
||||||
|
settlementAddresses.add(finalization.getHotspotSettlementAddress());
|
||||||
|
|
||||||
|
two.setupSettlementAddresses(settlementAddresses);
|
||||||
|
|
||||||
|
initialDigestsTwo = two.initialChannelDigests();
|
||||||
|
|
||||||
|
int timeoutMinutesServer = 2 * 60 * 1000;
|
||||||
|
|
||||||
|
this.channelRootAddress = finalization.getDepositAddressFlashChannel();
|
||||||
|
|
||||||
|
Accountant.getInstance().start(totalMegabytes, timeoutMinutesServer, totalMinutes, iotaDeposit, iotaPerMegabyte);
|
||||||
gson = new GsonBuilder().create();
|
gson = new GsonBuilder().create();
|
||||||
networkStatsManager = (NetworkStatsManager) context.getSystemService(Context.NETWORK_STATS_SERVICE);
|
networkStatsManager = (NetworkStatsManager) context.getSystemService(Context.NETWORK_STATS_SERVICE);
|
||||||
}
|
}
|
||||||
@ -152,16 +179,21 @@ public class BillingServer {
|
|||||||
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
|
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
|
||||||
// answer with billingOpenChannelAnswerString
|
// answer with billingOpenChannelAnswerString
|
||||||
|
|
||||||
|
// calculate ROOT ADDRESS
|
||||||
|
List<List<Digest>> digestPairs = new ArrayList<>();
|
||||||
|
digestPairs.add(billingOpenChannel.getClientDigests());
|
||||||
|
digestPairs.add(initialDigestsTwo);
|
||||||
|
|
||||||
// ToDo: create the flash channel
|
// This will create the initial multisig addresses and the root address.
|
||||||
|
two.setupChannelWithDigests(digestPairs);
|
||||||
|
|
||||||
|
Log.d("[ROOT ADDR]", two.getRootAddressWithChecksum());
|
||||||
|
|
||||||
BillingOpenChannelAnswer billingOpenChannelAnswer = new BillingOpenChannelAnswer(
|
BillingOpenChannelAnswer billingOpenChannelAnswer = new BillingOpenChannelAnswer(
|
||||||
Accountant.getInstance().getTotalIotaDeposit(),
|
Accountant.getInstance().getTotalIotaDeposit(),
|
||||||
Accountant.getInstance().getTotalIotaDeposit(),
|
Accountant.getInstance().getTotalIotaDeposit(),
|
||||||
hotspotRefundAddress,
|
two.getRootAddressWithChecksum(),
|
||||||
channelRootAddress,
|
initialDigestsTwo);
|
||||||
digests);
|
|
||||||
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
|
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
|
||||||
String billingOpenChannelAnswerString = gson.toJson(billingOpenChannelAnswer);
|
String billingOpenChannelAnswerString = gson.toJson(billingOpenChannelAnswer);
|
||||||
socketWrapper.sendLine(billingOpenChannelAnswerString);
|
socketWrapper.sendLine(billingOpenChannelAnswerString);
|
||||||
|
|||||||
@ -372,7 +372,9 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(TAG, "run: instantiate billing server");
|
Log.d(TAG, "run: instantiate billing server");
|
||||||
BillingServer billingServer = new BillingServer(mac, getApplicationContext());
|
// ToDo: Replace seedindex
|
||||||
|
int seedindex = 0;
|
||||||
|
BillingServer billingServer = new BillingServer(mac, getApplicationContext(), seed, seedindex);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
billingServer.start();
|
billingServer.start();
|
||||||
@ -403,7 +405,7 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
Runnable task = new Runnable() {
|
Runnable task = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
BillingClient billingClient = new BillingClient(mac, getApplicationContext());
|
BillingClient billingClient = new BillingClient(mac, getApplicationContext(), seed, 0); // ToDo: remove the magic number
|
||||||
// Gget the AP gateway ip address
|
// Gget the AP gateway ip address
|
||||||
// https://stackoverflow.com/questions/9035784/how-to-know-ip-address-of-the-router-from-code-in-android
|
// https://stackoverflow.com/questions/9035784/how-to-know-ip-address-of-the-router-from-code-in-android
|
||||||
final WifiManager manager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
final WifiManager manager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
@ -683,6 +685,10 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
|
|
||||||
|
|
||||||
public void startNegotiationServer(final boolean isClient, String macAddress, String peerMac) {
|
public void startNegotiationServer(final boolean isClient, String macAddress, String peerMac) {
|
||||||
|
// ToDo: settlementAddress
|
||||||
|
String settlementAddress = "RDNUSLPNOQUGDIZVOINTYRIRRIJMLODOC9ZTQU9KQSCDXPVSBILXUE9AHEOA9MNYZWNSECAVPQ9QSAHCN";
|
||||||
|
|
||||||
|
|
||||||
Runnable task = new Runnable() {
|
Runnable task = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -691,7 +697,8 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
macAddress,
|
macAddress,
|
||||||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()),
|
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()),
|
||||||
getBaseContext(),
|
getBaseContext(),
|
||||||
peerMac
|
peerMac,
|
||||||
|
"IUQDBHFDXK9EHKC9VUHCUXDLICLRANNDHYRMDYFCGSZMROWCZBLBNRKXWBSWZYDMLLHIHMP9ZPOPIFUSW"// settlementAddress
|
||||||
);
|
);
|
||||||
|
|
||||||
String peer_mac_address = null;
|
String peer_mac_address = null;
|
||||||
@ -763,7 +770,7 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
this.sendBroadcast(local);
|
this.sendBroadcast(local);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNegotiationClient(final InetAddress address, final boolean isClient, String macAddress, String peerMacAddress) {
|
public void startNegotiationClient(final InetAddress address, final boolean isClient, String macAddress, String peerMacAddress, String settlementAddress) {
|
||||||
Runnable task = new Runnable() {
|
Runnable task = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -772,7 +779,8 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
macAddress,
|
macAddress,
|
||||||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()),
|
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()),
|
||||||
getBaseContext(),
|
getBaseContext(),
|
||||||
peerMacAddress
|
peerMacAddress,
|
||||||
|
"RDNUSLPNOQUGDIZVOINTYRIRRIJMLODOC9ZTQU9KQSCDXPVSBILXUE9AHEOA9MNYZWNSECAVPQ9QSAHCN" //settlementAddress
|
||||||
);
|
);
|
||||||
String peer_mac_address = null;
|
String peer_mac_address = null;
|
||||||
boolean restartAfterwards = true;
|
boolean restartAfterwards = true;
|
||||||
@ -1229,7 +1237,9 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
startNegotiationServer(isInRoleConsumer(), ownerMac, clientMac);
|
startNegotiationServer(isInRoleConsumer(), ownerMac, clientMac);
|
||||||
} else {
|
} else {
|
||||||
InetAddress groupOwnerAddress = p2p_info.groupOwnerAddress;
|
InetAddress groupOwnerAddress = p2p_info.groupOwnerAddress;
|
||||||
startNegotiationClient(groupOwnerAddress, isInRoleConsumer(), clientMac, ownerMac);
|
// ToDo: get the settlementAddress
|
||||||
|
String settlementAddress = "RDNUSLPNOQUGDIZVOINTYRIRRIJMLODOC9ZTQU9KQSCDXPVSBILXUE9AHEOA9MNYZWNSECAVPQ9QSAHCN";
|
||||||
|
startNegotiationClient(groupOwnerAddress, isInRoleConsumer(), clientMac, ownerMac, settlementAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ public class Negotiator {
|
|||||||
private static final int clientTimeoutMillis = 5000;
|
private static final int clientTimeoutMillis = 5000;
|
||||||
private static final int serverTimeoutMillis = 5000;
|
private static final int serverTimeoutMillis = 5000;
|
||||||
private final String peerMac;
|
private final String peerMac;
|
||||||
|
private final String clientSettlementAddress;
|
||||||
private String ownMacAddress;
|
private String ownMacAddress;
|
||||||
|
|
||||||
private SocketWrapper socketWrapper;
|
private SocketWrapper socketWrapper;
|
||||||
@ -83,13 +84,14 @@ public class Negotiator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Negotiator(boolean isConsumer, String ownMacAddress, SharedPreferences prefs, Context context,
|
public Negotiator(boolean isConsumer, String ownMacAddress, SharedPreferences prefs, Context context,
|
||||||
String peerMac) {
|
String peerMac, String clientSettlementAddress) {
|
||||||
this.peerMac = peerMac;
|
this.peerMac = peerMac;
|
||||||
this.isConsumer = isConsumer;
|
this.isConsumer = isConsumer;
|
||||||
gson = new GsonBuilder().create();
|
gson = new GsonBuilder().create();
|
||||||
this.ownMacAddress = ownMacAddress;
|
this.ownMacAddress = ownMacAddress;
|
||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.clientSettlementAddress = clientSettlementAddress;
|
||||||
Log.d(TAG, "Negotiator: " + ownMacAddress);
|
Log.d(TAG, "Negotiator: " + ownMacAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +276,8 @@ public class Negotiator {
|
|||||||
String defaultValue = "0";
|
String defaultValue = "0";
|
||||||
String storedBalance = sharedPref.getString("balance", defaultValue);
|
String storedBalance = sharedPref.getString("balance", defaultValue);
|
||||||
int iotaBalance = Integer.parseInt(storedBalance);
|
int iotaBalance = Integer.parseInt(storedBalance);
|
||||||
|
// ToDo: remove the mock
|
||||||
|
iotaBalance = 100000;
|
||||||
|
|
||||||
Log.d(TAG, "runConsumerProtocol: MY IOTA BALANCE: " + iotaBalance);
|
Log.d(TAG, "runConsumerProtocol: MY IOTA BALANCE: " + iotaBalance);
|
||||||
|
|
||||||
@ -285,7 +289,7 @@ public class Negotiator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SEND NegotiationAnswer
|
// SEND NegotiationAnswer
|
||||||
NegotiationOfferAnswer answer = new NegotiationOfferAnswer(agree, client_roaming_minutes, ownMacAddress);
|
NegotiationOfferAnswer answer = new NegotiationOfferAnswer(agree, client_roaming_minutes, ownMacAddress, clientSettlementAddress);
|
||||||
PeerStore.getInstance().setLatestOfferAnswer(otherMac, answer);
|
PeerStore.getInstance().setLatestOfferAnswer(otherMac, answer);
|
||||||
String answerString = gson.toJson(answer);
|
String answerString = gson.toJson(answer);
|
||||||
socketWrapper.sendLine(answerString);
|
socketWrapper.sendLine(answerString);
|
||||||
@ -342,6 +346,8 @@ public class Negotiator {
|
|||||||
String defaultValue = "0";
|
String defaultValue = "0";
|
||||||
String storedBalance = sharedPref.getString("balance", defaultValue);
|
String storedBalance = sharedPref.getString("balance", defaultValue);
|
||||||
int iotaBalance = Integer.parseInt(storedBalance);
|
int iotaBalance = Integer.parseInt(storedBalance);
|
||||||
|
// ToDo: remove the mock
|
||||||
|
iotaBalance = 100000;
|
||||||
|
|
||||||
// Assumption 1 MB per minute
|
// Assumption 1 MB per minute
|
||||||
if (iotaBalance < maxMinutes * iotaPerMegabyte) {
|
if (iotaBalance < maxMinutes * iotaPerMegabyte) {
|
||||||
@ -404,14 +410,15 @@ public class Negotiator {
|
|||||||
// ToDo: get depositAddressFlashChannel from SharedPreferences
|
// ToDo: get depositAddressFlashChannel from SharedPreferences
|
||||||
// ToDo: get the bandwidth of the hotspot
|
// ToDo: get the bandwidth of the hotspot
|
||||||
// ToDo: create initial flash object
|
// ToDo: create initial flash object
|
||||||
double bandwidth = 0.1; // megabyte per second;
|
double bandwidth = 1.0; // megabyte per second;
|
||||||
int max_data_volume_megabytes = (int) (answer.getDuranceInMinutes() * bandwidth);
|
int max_data_volume_megabytes = (int) (answer.getDuranceInMinutes() * bandwidth);
|
||||||
int max_iota_transferred = max_data_volume_megabytes * offer.getIotaPerMegabyte();
|
int max_iota_transferred = max_data_volume_megabytes * offer.getIotaPerMegabyte();
|
||||||
max_iota_transferred = 10;
|
max_iota_transferred = 10;
|
||||||
String rootAddress = "JZWUMRUEYFJOCDDRZCNIIMDZSX9LWMITNMDIAIUJKUV9LVDLSICDABFYTTBZFGEBJOADDN9WZ9IJJJD9DXRJRR9TOW";
|
String rootAddress = "JZWUMRUEYFJOCDDRZCNIIMDZSX9LWMITNMDIAIUJKUV9LVDLSICDABFYTTBZFGEBJOADDN9WZ9IJJJD9DXRJRR9TOW";
|
||||||
|
String hotspotSettlementAddress = "IUQDBHFDXK9EHKC9VUHCUXDLICLRANNDHYRMDYFCGSZMROWCZBLBNRKXWBSWZYDMLLHIHMP9ZPOPIFUSW";
|
||||||
// send the most important message to the user
|
// send the most important message to the user
|
||||||
NegotiationFinalization finalization = new NegotiationFinalization(hotspotName, password,
|
NegotiationFinalization finalization = new NegotiationFinalization(hotspotName, password,
|
||||||
rootAddress, max_iota_transferred, max_iota_transferred, "<flashObj>");
|
rootAddress, max_iota_transferred, max_iota_transferred, hotspotSettlementAddress);
|
||||||
PeerStore.getInstance().setLatestFinalization(otherMac, finalization);
|
PeerStore.getInstance().setLatestFinalization(otherMac, finalization);
|
||||||
String finalizationString = gson.toJson(finalization);
|
String finalizationString = gson.toJson(finalization);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
package com.flashwifi.wifip2p.protocol;
|
package com.flashwifi.wifip2p.protocol;
|
||||||
|
|
||||||
|
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.Model.Digest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BillingOpenChannel {
|
public class BillingOpenChannel {
|
||||||
private int totalMegabytes;
|
private int totalMegabytes;
|
||||||
private int totalMinutes;
|
private int totalMinutes;
|
||||||
@ -8,10 +12,10 @@ public class BillingOpenChannel {
|
|||||||
private int timeoutMinutesClient;
|
private int timeoutMinutesClient;
|
||||||
private String clientRefundAddress;
|
private String clientRefundAddress;
|
||||||
private int treeDepth;
|
private int treeDepth;
|
||||||
private String[] clientDigests;
|
private List<Digest> clientDigests;
|
||||||
|
|
||||||
public BillingOpenChannel(int totalMegabytes, int iotaPerMegabyte, String clientRefundAddress,
|
public BillingOpenChannel(int totalMegabytes, int iotaPerMegabyte,
|
||||||
int treeDepth, String[] clientDigests, int timeoutMinutesClient,
|
int treeDepth, List<Digest> clientDigests, int timeoutMinutesClient,
|
||||||
int totalMinutes) {
|
int totalMinutes) {
|
||||||
this.totalMegabytes = totalMegabytes;
|
this.totalMegabytes = totalMegabytes;
|
||||||
this.totalMinutes = totalMinutes;
|
this.totalMinutes = totalMinutes;
|
||||||
@ -34,15 +38,12 @@ public class BillingOpenChannel {
|
|||||||
return iotaPerMegabyte;
|
return iotaPerMegabyte;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientRefundAddress() {
|
|
||||||
return clientRefundAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTreeDepth() {
|
public int getTreeDepth() {
|
||||||
return treeDepth;
|
return treeDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getClientDigests() {
|
public List<Digest> getClientDigests() {
|
||||||
return clientDigests;
|
return clientDigests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,20 @@
|
|||||||
package com.flashwifi.wifip2p.protocol;
|
package com.flashwifi.wifip2p.protocol;
|
||||||
|
|
||||||
|
|
||||||
|
import com.flashwifi.wifip2p.iotaFlashWrapper.Model.Digest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BillingOpenChannelAnswer {
|
public class BillingOpenChannelAnswer {
|
||||||
private int hotspotDepositIota;
|
private int hotspotDepositIota;
|
||||||
private int clientDepositIota;
|
private int clientDepositIota;
|
||||||
private int timeoutMinutesHotspot;
|
private int timeoutMinutesHotspot;
|
||||||
private String hotspotRefundAddress;
|
|
||||||
private String channelRootAddress;
|
private String channelRootAddress;
|
||||||
private String[] hotspotDigests;
|
private List<Digest> hotspotDigests;
|
||||||
|
|
||||||
public BillingOpenChannelAnswer(int hotspotDepositIota, int clientDepositIota, String hotspotRefundAddress, String channelRootAddress, String[] hotspotDigests) {
|
public BillingOpenChannelAnswer(int hotspotDepositIota, int clientDepositIota, String channelRootAddress, List<Digest> hotspotDigests) {
|
||||||
this.hotspotDepositIota = hotspotDepositIota;
|
this.hotspotDepositIota = hotspotDepositIota;
|
||||||
this.clientDepositIota = clientDepositIota;
|
this.clientDepositIota = clientDepositIota;
|
||||||
this.hotspotRefundAddress = hotspotRefundAddress;
|
|
||||||
this.channelRootAddress = channelRootAddress;
|
this.channelRootAddress = channelRootAddress;
|
||||||
this.hotspotDigests = hotspotDigests;
|
this.hotspotDigests = hotspotDigests;
|
||||||
}
|
}
|
||||||
@ -29,15 +31,11 @@ public class BillingOpenChannelAnswer {
|
|||||||
return timeoutMinutesHotspot;
|
return timeoutMinutesHotspot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHotspotRefundAddress() {
|
|
||||||
return hotspotRefundAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChannelRootAddress() {
|
public String getChannelRootAddress() {
|
||||||
return channelRootAddress;
|
return channelRootAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getHotspotDigests() {
|
public List<Digest> getHotspotDigests() {
|
||||||
return hotspotDigests;
|
return hotspotDigests;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,18 @@ public class NegotiationFinalization {
|
|||||||
private String hotspotName;
|
private String hotspotName;
|
||||||
private String hotspotPassword;
|
private String hotspotPassword;
|
||||||
private String depositAddressFlashChannel;
|
private String depositAddressFlashChannel;
|
||||||
private String clientRefundAddress;
|
private String hotspotSettlementAddress;
|
||||||
private String hotspotRefundAddress;
|
|
||||||
private int depositServerFlashChannelInIota;
|
private int depositServerFlashChannelInIota;
|
||||||
private int depositClientFlashChannelInIota;
|
private int depositClientFlashChannelInIota;
|
||||||
private String flashObject;
|
|
||||||
|
|
||||||
public NegotiationFinalization(String hotspotName, String hotspotPassword, String depositAddressFlashChannel, int depositServerFlashChannelInIota, int depositClientFlashChannelInIota, String flashObject) {
|
public NegotiationFinalization(String hotspotName, String hotspotPassword, String depositAddressFlashChannel, int depositServerFlashChannelInIota, int depositClientFlashChannelInIota, String hotspotSettlementAddress) {
|
||||||
this.type = "negotiationFinalization";
|
this.type = "negotiationFinalization";
|
||||||
this.hotspotName = hotspotName;
|
this.hotspotName = hotspotName;
|
||||||
this.hotspotPassword = hotspotPassword;
|
this.hotspotPassword = hotspotPassword;
|
||||||
this.depositAddressFlashChannel = depositAddressFlashChannel;
|
this.depositAddressFlashChannel = depositAddressFlashChannel;
|
||||||
this.depositServerFlashChannelInIota = depositServerFlashChannelInIota;
|
this.depositServerFlashChannelInIota = depositServerFlashChannelInIota;
|
||||||
this.depositClientFlashChannelInIota = depositClientFlashChannelInIota;
|
this.depositClientFlashChannelInIota = depositClientFlashChannelInIota;
|
||||||
this.flashObject = flashObject;
|
this.hotspotSettlementAddress = hotspotSettlementAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHotspotName() {
|
public String getHotspotName() {
|
||||||
@ -42,15 +40,7 @@ public class NegotiationFinalization {
|
|||||||
return depositClientFlashChannelInIota;
|
return depositClientFlashChannelInIota;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFlashObject() {
|
public String getHotspotSettlementAddress() {
|
||||||
return flashObject;
|
return hotspotSettlementAddress;
|
||||||
}
|
|
||||||
|
|
||||||
public String getClientRefundAddress() {
|
|
||||||
return clientRefundAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHotspotRefundAddress() {
|
|
||||||
return hotspotRefundAddress;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,14 @@ public class NegotiationOfferAnswer {
|
|||||||
private boolean agreeToConditions;
|
private boolean agreeToConditions;
|
||||||
private int duranceInMinutes;
|
private int duranceInMinutes;
|
||||||
private String consumerMac;
|
private String consumerMac;
|
||||||
|
private String clientSettlementAddress;
|
||||||
|
|
||||||
public NegotiationOfferAnswer(boolean agreeToConditions, int duranceInMinutes, String consumerMac) {
|
public NegotiationOfferAnswer(boolean agreeToConditions, int duranceInMinutes, String consumerMac, String clientSettlementAddress) {
|
||||||
this.type = "answerToOffer";
|
this.type = "answerToOffer";
|
||||||
this.agreeToConditions = agreeToConditions;
|
this.agreeToConditions = agreeToConditions;
|
||||||
this.duranceInMinutes = duranceInMinutes;
|
this.duranceInMinutes = duranceInMinutes;
|
||||||
this.consumerMac = consumerMac;
|
this.consumerMac = consumerMac;
|
||||||
|
this.clientSettlementAddress = clientSettlementAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
@ -29,4 +31,8 @@ public class NegotiationOfferAnswer {
|
|||||||
public String getConsumerMac() {
|
public String getConsumerMac() {
|
||||||
return consumerMac;
|
return consumerMac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientSettlementAddress() {
|
||||||
|
return clientSettlementAddress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user