This commit is contained in:
Daniel Pollithy 2018-01-23 00:25:58 +01:00
parent 010ce3b272
commit bd623711f7
11 changed files with 420 additions and 17 deletions

View File

@ -30,6 +30,7 @@ import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.Toast;
import com.flashwifi.wifip2p.billing.Accountant;
import com.flashwifi.wifip2p.broadcast.WiFiDirectBroadcastService;
public class MainActivity extends AppCompatActivity
@ -71,6 +72,8 @@ public class MainActivity extends AppCompatActivity
} else if (intent.getAction().equals("com.flashwifi.wifip2p.stop_roaming")) {
Log.d(TAG, "onReceive: Reset billing state");
mService.resetBillingState();
mService.setInRoleConsumer(false);
mService.setInRoleHotspot(false);
}
}
};
@ -137,6 +140,8 @@ public class MainActivity extends AppCompatActivity
password = intent.getStringExtra("password");
seed = intent.getStringExtra("seed");
Accountant.getInstance().setSeed(seed);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

View File

@ -32,6 +32,7 @@ import android.widget.TextView;
import android.widget.Toast;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import com.flashwifi.wifip2p.billing.Accountant;
@ -98,6 +99,7 @@ public class RoamingActivity extends AppCompatActivity {
Log.d(TAG, "updateUi: message=" + message);
CheckBox apConnected = (CheckBox)findViewById(R.id.accessPointActive);
CheckBox flashEstablished = (CheckBox)findViewById(R.id.flashEstablished);
CheckBox channelFunded = (CheckBox)findViewById(R.id.channelFunded);
if (message.equals("AP SUCCESS")) {
apConnected.setChecked(true);
mService.resetBillingState();
@ -111,6 +113,11 @@ public class RoamingActivity extends AppCompatActivity {
apConnected.setChecked(false);
} else if (message.equals("Channel established")) {
flashEstablished.setChecked(true);
} else if (message.equals("Start Channel funding")) {
// start the task
mService.fundChannel(address);
} else if (message.equals("Channel funded")) {
channelFunded.setChecked(true);
} else if (message.equals("Billing")) {
updateBillingCard();
} else if (message.equals("Channel closed")) {
@ -188,9 +195,9 @@ public class RoamingActivity extends AppCompatActivity {
private void startBillingProtocol() {
// setup the flash channel etc...
if (mService.isInRoleHotspot()) {
mService.startBillingServer();
mService.startBillingServer(address);
} else {
mService.startBillingClient();
mService.startBillingClient(address);
}
}

View File

@ -22,6 +22,7 @@ public class Accountant {
private FlashChannelHelper flashChannelHelper;
private boolean closed = true;
private String seed;
public static Accountant getInstance() {
return ourInstance;
@ -180,4 +181,12 @@ public class Accountant {
public double getIotaPerByte() {
return ((double)getIotaPerMegaByte()) / (1024.0d * 1024.0d);
}
public void setSeed(String seed) {
this.seed = seed;
}
public String getSeed() {
return seed;
}
}

View File

@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.flashwifi.wifip2p.datastore.PeerInformation;
import com.flashwifi.wifip2p.datastore.PeerStore;
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
import com.flashwifi.wifip2p.protocol.BillMessage;
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
@ -12,6 +14,9 @@ import com.flashwifi.wifip2p.protocol.BillingCloseChannel;
import com.flashwifi.wifip2p.protocol.BillingCloseChannelAnswer;
import com.flashwifi.wifip2p.protocol.BillingOpenChannel;
import com.flashwifi.wifip2p.protocol.BillingOpenChannelAnswer;
import com.flashwifi.wifip2p.protocol.NegotiationFinalization;
import com.flashwifi.wifip2p.protocol.NegotiationOffer;
import com.flashwifi.wifip2p.protocol.NegotiationOfferAnswer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -31,6 +36,7 @@ import java.net.UnknownHostException;
public class BillingClient {
private static final String TAG = "BillingClient";
private final Gson gson;
private final String mac;
private State state = State.NOT_PAIRED;
private Socket socket;
private SocketWrapper socketWrapper;
@ -51,8 +57,9 @@ public class BillingClient {
context.sendBroadcast(local);
}
public BillingClient(Context context){
public BillingClient(String mac, Context context){
this.context = context;
this.mac = mac;
gson = new GsonBuilder().create();
}
@ -78,20 +85,39 @@ public class BillingClient {
String hotspotStateLine = socketWrapper.getLineThrowing();
if (hotspotStateLine.contains("INITIAL") || hotspotStateLine.contains("NOT_PAIRED")) {
// ask the hotspot to open the flash channel
// ToDo: get real digests
// get the negotiated data
NegotiationOffer offer = PeerStore.getInstance().getLatestNegotiationOffer(mac);
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
// get the necessary values
// ToDo: replace magic number with setting
int totalMegabytes = 100;
int treeDepth = 8;
String[] digests = new String[]{"1234", "2345", "3456"};
// ToDo: replace magic numbers
billingOpenChannel = new BillingOpenChannel(100, 100, "clientAddress", 8, digests, 20 * 60 * 1000, 60);
int timeoutMinutesClient = 20 * 60 * 1000;
int iotaPerMegabyte = offer.getIotaPerMegabyte();
String clientRefundAddress = finalization.getClientRefundAddress();
int totalMinutes = answer.getDuranceInMinutes();
billingOpenChannel = new BillingOpenChannel(totalMegabytes, iotaPerMegabyte, clientRefundAddress, treeDepth, digests, timeoutMinutesClient, totalMinutes);
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
String billingOpenChannelString = gson.toJson(billingOpenChannel);
socketWrapper.sendLine(billingOpenChannelString);
// receive the hotspot details for the flash channel
String billingOpenChannelAnswerString = socketWrapper.getLineThrowing();
billingOpenChannelAnswer = gson.fromJson(billingOpenChannelAnswerString, BillingOpenChannelAnswer.class);
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
// now create the flash channel on our side
Accountant.getInstance().start(billingOpenChannel.getTotalMegabytes(), billingOpenChannel.getTimeoutMinutesClient(), billingOpenChannel.getTotalMinutes(), billingOpenChannelAnswer.getClientDepositIota(),
billingOpenChannel.getIotaPerMegabyte());
sendUpdateUIBroadcastWithMessage("Channel established");
state = State.ROAMING;
// start the task to fund the channel
sendUpdateUIBroadcastWithMessage("Start Channel funding");
} else {
// what to do if the hotspot already created stuff and was in roaming mode
// ToDo: ^^^^^

View File

@ -10,6 +10,7 @@ import android.os.RemoteException;
import android.text.format.Formatter;
import android.util.Log;
import com.flashwifi.wifip2p.datastore.PeerStore;
import com.flashwifi.wifip2p.negotiation.SocketWrapper;
import com.flashwifi.wifip2p.protocol.BillMessage;
import com.flashwifi.wifip2p.protocol.BillMessageAnswer;
@ -17,6 +18,9 @@ import com.flashwifi.wifip2p.protocol.BillingCloseChannel;
import com.flashwifi.wifip2p.protocol.BillingCloseChannelAnswer;
import com.flashwifi.wifip2p.protocol.BillingOpenChannel;
import com.flashwifi.wifip2p.protocol.BillingOpenChannelAnswer;
import com.flashwifi.wifip2p.protocol.NegotiationFinalization;
import com.flashwifi.wifip2p.protocol.NegotiationOffer;
import com.flashwifi.wifip2p.protocol.NegotiationOfferAnswer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -41,6 +45,10 @@ import static android.content.Context.WIFI_SERVICE;
public class BillingServer {
private static final String TAG = "BillingServer";
private final Gson gson;
private final String mac;
private final String hotspotRefundAddress;
private final String channelRootAddress;
private final String[] digests;
private State state = State.NOT_PAIRED;
private ServerSocket serverSocket;
private Socket socket;
@ -58,9 +66,31 @@ public class BillingServer {
context.sendBroadcast(local);
}
public BillingServer(int bookedMegabytes, int timeoutMinutes, int maxMinutes, int iotaDepositClient, int iotaPerMegabyte, Context context){
public BillingServer(String mac, Context context){
this.context = context;
Accountant.getInstance().start(bookedMegabytes, timeoutMinutes, maxMinutes, iotaDepositClient, iotaPerMegabyte);
this.mac = mac;
// get the negotiated data
NegotiationOffer offer = PeerStore.getInstance().getLatestNegotiationOffer(mac);
NegotiationOfferAnswer answer = PeerStore.getInstance().getLatestNegotiationOfferAnswer(mac);
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(mac);
// 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 = 20 * 60 * 1000;
this.hotspotRefundAddress = finalization.getHotspotRefundAddress();
this.channelRootAddress = finalization.getDepositAddressFlashChannel();
int iotaPerMegabyte = offer.getIotaPerMegabyte();
int iotaDepositClient = totalMegabytes * iotaPerMegabyte;
String clientRefundAddress = finalization.getClientRefundAddress();
int totalMinutes = answer.getDuranceInMinutes();
Accountant.getInstance().start(totalMegabytes, timeoutMinutesServer, totalMinutes, iotaDepositClient, iotaPerMegabyte);
gson = new GsonBuilder().create();
networkStatsManager = (NetworkStatsManager) context.getSystemService(Context.NETWORK_STATS_SERVICE);
}
@ -101,11 +131,20 @@ public class BillingServer {
// receive the BillingOpenChannel message
String billingOpenChannelString = socketWrapper.getLineThrowing();
BillingOpenChannel billingOpenChannel = gson.fromJson(billingOpenChannelString, BillingOpenChannel.class);
PeerStore.getInstance().setLatestBillingOpenChannel(mac, billingOpenChannel);
// answer with billingOpenChannelAnswerString
// ToDo: create the flash channel
String[] myDigests = new String[]{"1234", "2345", "3456"};
BillingOpenChannelAnswer billingOpenChannelAnswer = new BillingOpenChannelAnswer(1000, 1000, "", "", myDigests);
BillingOpenChannelAnswer billingOpenChannelAnswer = new BillingOpenChannelAnswer(
Accountant.getInstance().getTotalIotaDeposit(),
Accountant.getInstance().getTotalIotaDeposit(),
hotspotRefundAddress,
channelRootAddress,
digests);
PeerStore.getInstance().setLatestBillingOpenChannelAnswer(mac, billingOpenChannelAnswer);
String billingOpenChannelAnswerString = gson.toJson(billingOpenChannelAnswer);
socketWrapper.sendLine(billingOpenChannelAnswerString);
@ -113,6 +152,9 @@ public class BillingServer {
// OK
state = State.ROAMING;
// start funding
sendUpdateUIBroadcastWithMessage("Start Channel funding");
}
if (state == State.ROAMING) {

View File

@ -5,6 +5,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pConfig;
@ -14,18 +15,28 @@ import android.net.wifi.p2p.WifiP2pInfo;
import android.net.wifi.p2p.WifiP2pManager;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import com.flashwifi.wifip2p.AddressBalanceTransfer;
import com.flashwifi.wifip2p.accesspoint.AccessPointTask;
import com.flashwifi.wifip2p.accesspoint.ConnectTask;
import com.flashwifi.wifip2p.accesspoint.StopAccessPointTask;
import com.flashwifi.wifip2p.billing.Accountant;
import com.flashwifi.wifip2p.billing.BillingClient;
import com.flashwifi.wifip2p.billing.BillingServer;
import com.flashwifi.wifip2p.datastore.PeerStore;
import com.flashwifi.wifip2p.iotaAPI.Requests.WalletTransferRequest;
import com.flashwifi.wifip2p.negotiation.Negotiator;
import com.flashwifi.wifip2p.protocol.BillingOpenChannel;
import com.flashwifi.wifip2p.protocol.BillingOpenChannelAnswer;
import com.flashwifi.wifip2p.protocol.NegotiationFinalization;
import com.flashwifi.wifip2p.protocol.NegotiationOffer;
import com.flashwifi.wifip2p.protocol.NegotiationOfferAnswer;
import java.io.IOException;
import java.lang.reflect.Method;
@ -35,6 +46,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import jota.IotaAPI;
import jota.dto.response.GetBalancesResponse;
import jota.dto.response.SendTransferResponse;
import jota.error.ArgumentException;
import jota.model.Transfer;
public class WiFiDirectBroadcastService extends Service {
public final static String TAG = "WiFiService";
@ -106,7 +123,7 @@ public class WiFiDirectBroadcastService extends Service {
billingServerIsRunning = false;
}
public void startBillingServer(){
public void startBillingServer(String mac){
if (!billingServerIsRunning) {
billingServerIsRunning = true;
@ -115,7 +132,7 @@ public class WiFiDirectBroadcastService extends Service {
public void run() {
Log.d(TAG, "run: instantiate billing server");
// ToDo: remove magic numbers
BillingServer billingServer = new BillingServer(10, 20, 30, 10000, 1000, getApplicationContext());
BillingServer billingServer = new BillingServer(mac, getApplicationContext());
try {
billingServer.start();
@ -138,7 +155,7 @@ public class WiFiDirectBroadcastService extends Service {
}
public void startBillingClient() {
public void startBillingClient(String mac) {
if (!billingClientIsRunning) {
billingClientIsRunning = true;
@ -147,8 +164,7 @@ public class WiFiDirectBroadcastService extends Service {
Runnable task = new Runnable() {
@Override
public void run() {
// ToDo: remove magic numbers
BillingClient billingClient = new BillingClient(getApplicationContext());
BillingClient billingClient = new BillingClient(mac, getApplicationContext());
// ToDo: get the AP gateway ip address
// https://stackoverflow.com/questions/9035784/how-to-know-ip-address-of-the-router-from-code-in-android
billingClient.start("192.168.43.1");
@ -485,6 +501,171 @@ public class WiFiDirectBroadcastService extends Service {
}
public void fundChannel(String address) {
// get the necessary data
NegotiationOffer offer = PeerStore.getInstance().getLatestNegotiationOffer(address);
NegotiationOfferAnswer offerAnser = PeerStore.getInstance().getLatestNegotiationOfferAnswer(address);
NegotiationFinalization finalization = PeerStore.getInstance().getLatestFinalization(address);
BillingOpenChannel openChannel = PeerStore.getInstance().getPeer(address).getBillingOpenChannel();
BillingOpenChannelAnswer openChannelAnswer = PeerStore.getInstance().getPeer(address).getBillingOpenChannelAnswer();
String multisigAddress = finalization.getDepositAddressFlashChannel();
int timeoutClientSeconds = openChannel.getTimeoutMinutesClient();
int timeoutHotspotSeconds = openChannelAnswer.getTimeoutMinutesHotspot() * 60;
int timeout = (isInRoleHotspot()) ? timeoutHotspotSeconds : timeoutClientSeconds;
int clientDeposit = finalization.getDepositClientFlashChannelInIota();
int hotspotDeposit = finalization.getDepositServerFlashChannelInIota();
int deposit = (isInRoleHotspot()) ? hotspotDeposit : clientDeposit;
int depositTogether = clientDeposit + hotspotDeposit;
String seed = Accountant.getInstance().getSeed();
Log.d(TAG, "fundChannel: Let's fund " + multisigAddress);
Runnable task = () -> {
Log.d(TAG, "run: fund multisig address");
boolean fundDone = false;
boolean fundIsThere = false;
int fundErrorCount = 0;
int maxFundErrors = 10;
SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean testnet = prefManager.getBoolean("pref_key_switch_testnet",false);
IotaAPI api;
if(testnet){
//Testnet node:
api = new IotaAPI.Builder()
.protocol("https")
.host("testnet140.tangle.works")
.port("443")
.build();
}
else{
//Mainnet node:
api = new IotaAPI.Builder()
.protocol("http")
.host("node.iotawallet.info")
.port("14265")
.build();
}
long start = System.currentTimeMillis() / 1000L;
while (((System.currentTimeMillis()/1000L) - start < timeout || !fundDone || !fundIsThere) && fundErrorCount < maxFundErrors) {
SendTransferResponse sendTransferResponse = null;
if (!fundDone) {
Log.d(TAG, "fundChannel: DEPOSIT::" + Integer.toString(deposit));
try {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new Transfer(multisigAddress, deposit, "", ""));
if(testnet) {
Log.d(TAG, "fundChannel: fund on testnet");
sendTransferResponse = api.sendTransfer(seed, 2, 4, 9, transfers, null, null, false);
}
else{
Log.d(TAG, "fundChannel: fund on mainnet");
sendTransferResponse = api.sendTransfer(seed, 2, 4, 18, transfers, null, null, false);
}
} catch (ArgumentException | IllegalAccessError | IllegalStateException e) {
String transferResult = "";
if (e instanceof ArgumentException) {
if (e.getMessage().contains("Sending to a used address.") || e.getMessage().contains("Private key reuse detect!") || e.getMessage().contains("Send to inputs!")) {
transferResult = "Sending to a used address/Private key reuse detect. Error Occurred.";
}
else if(e.getMessage().contains("Failed to connect to node")){
transferResult = "Failed to connect to node";
}
else{
transferResult = "Network Error: Attaching new address failed or Transaction failed";
}
}
if (e instanceof IllegalAccessError) {
transferResult = "Local POW needs to be enabled";
}
fundErrorCount++;
Log.d(TAG, "fundChannel: " + transferResult);
}
if(sendTransferResponse != null){
Boolean[] transferSuccess = sendTransferResponse.getSuccessfully();
Boolean success = true;
for (Boolean status : transferSuccess) {
if(status.equals(false)){
success = false;
fundErrorCount++;
break;
}
}
if(success){
Log.d(TAG, "fundChannel: successfully transferred my part");
fundDone = true;
}
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else if (fundDone && !fundIsThere) {
// now check the balance until we get it
// check the funding
Log.d(TAG, "fundChannel: checking the balance of the root...");
List<String> addresses = new ArrayList<String>();
addresses.add(multisigAddress);
GetBalancesResponse response = null;
try {
response = api.getBalances(100, addresses);
} catch (ArgumentException e) {
e.printStackTrace();
}
if (response != null) {
if (response.getBalances().length > 0) {
long balance = Integer.parseInt(response.getBalances()[0]);
Log.d(TAG, "fundChannel: Found balance " + response.getBalances()[0]);
if (balance > depositTogether) {
Log.d(TAG, "fundChannel: balance is enough on both sides");
fundIsThere = true;
}
}
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (fundErrorCount < maxFundErrors) {
Log.d(TAG, "fundChannel: channel funded");
sendUpdateRoamingBroadcastWithMessage("Channel funded");
} else {
Log.d(TAG, "fundChannel: too many fund errors");
}
};
Log.d(TAG, "startFunding");
Thread thread = new Thread(task);
threads.add(thread);
thread.start();
}
/**
* Class used for the client Binder. Because we know this service always
@ -578,6 +759,13 @@ public class WiFiDirectBroadcastService extends Service {
this.sendBroadcast(local);
}
private void sendUpdateRoamingBroadcastWithMessage(String message){
Intent local = new Intent();
local.putExtra("message", message);
local.setAction("com.flashwifi.wifip2p.update_roaming");
this.sendBroadcast(local);
}
public void connect(String address, WifiP2pManager.ActionListener actionListener) {
WifiP2pDevice device;
WifiP2pConfig config = new WifiP2pConfig();

View File

@ -4,6 +4,10 @@ import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pInfo;
import android.support.annotation.NonNull;
import com.flashwifi.wifip2p.protocol.BillingCloseChannel;
import com.flashwifi.wifip2p.protocol.BillingCloseChannelAnswer;
import com.flashwifi.wifip2p.protocol.BillingOpenChannel;
import com.flashwifi.wifip2p.protocol.BillingOpenChannelAnswer;
import com.flashwifi.wifip2p.protocol.NegotiationFinalization;
import com.flashwifi.wifip2p.protocol.NegotiationOffer;
import com.flashwifi.wifip2p.protocol.NegotiationOfferAnswer;
@ -27,6 +31,11 @@ public class PeerInformation {
private NegotiationOfferAnswer latestOfferAnswer;
private NegotiationFinalization latestFinalization;
private BillingOpenChannel billingOpenChannel;
private BillingOpenChannelAnswer billingOpenChannelAnswer;
private BillingCloseChannel billingCloseChannel;
private BillingCloseChannelAnswer billingCloseChannelAnswer;
public PeerInformation() {
selected = false;
age = 0;
@ -56,6 +65,8 @@ public class PeerInformation {
return latestNegotiationOffer;
}
public void setLatestOfferAnswer(NegotiationOfferAnswer latestOfferAnswer) {
this.latestOfferAnswer = latestOfferAnswer;
}
@ -95,4 +106,36 @@ public class PeerInformation {
public String getErrorMessage() {
return errorMessage;
}
public BillingOpenChannel getBillingOpenChannel() {
return billingOpenChannel;
}
public void setBillingOpenChannel(BillingOpenChannel billingOpenChannel) {
this.billingOpenChannel = billingOpenChannel;
}
public BillingOpenChannelAnswer getBillingOpenChannelAnswer() {
return billingOpenChannelAnswer;
}
public void setBillingOpenChannelAnswer(BillingOpenChannelAnswer billingOpenChannelAnswer) {
this.billingOpenChannelAnswer = billingOpenChannelAnswer;
}
public BillingCloseChannel getBillingCloseChannel() {
return billingCloseChannel;
}
public void setBillingCloseChannel(BillingCloseChannel billingCloseChannel) {
this.billingCloseChannel = billingCloseChannel;
}
public BillingCloseChannelAnswer getBillingCloseChannelAnswer() {
return billingCloseChannelAnswer;
}
public void setBillingCloseChannelAnswer(BillingCloseChannelAnswer billingCloseChannelAnswer) {
this.billingCloseChannelAnswer = billingCloseChannelAnswer;
}
}

View File

@ -1,5 +1,9 @@
package com.flashwifi.wifip2p.datastore;
import com.flashwifi.wifip2p.protocol.BillingCloseChannel;
import com.flashwifi.wifip2p.protocol.BillingCloseChannelAnswer;
import com.flashwifi.wifip2p.protocol.BillingOpenChannel;
import com.flashwifi.wifip2p.protocol.BillingOpenChannelAnswer;
import com.flashwifi.wifip2p.protocol.NegotiationFinalization;
import com.flashwifi.wifip2p.protocol.NegotiationOffer;
import com.flashwifi.wifip2p.protocol.NegotiationOfferAnswer;
@ -116,8 +120,46 @@ public class PeerStore {
return null;
}
public NegotiationOffer getLatestNegotiationOffer(String macAddress) {
if (peers.containsKey(macAddress.toLowerCase())) {
return peers.get(macAddress.toLowerCase()).getLatestNegotiationOffer();
}
return null;
}
public NegotiationOfferAnswer getLatestNegotiationOfferAnswer(String macAddress) {
if (peers.containsKey(macAddress.toLowerCase())) {
return peers.get(macAddress.toLowerCase()).getLatestOfferAnswer();
}
return null;
}
public void setIPAddress(String macAddress, InetAddress IPAddress) {
getOrCreatePeer(macAddress.toLowerCase()).setIPAddress(IPAddress.getHostAddress());
}
public void setLatestBillingOpenChannel(String macAddress, BillingOpenChannel o) {
getOrCreatePeer(macAddress.toLowerCase()).setBillingOpenChannel(o);
}
public void setLatestBillingOpenChannelAnswer(String macAddress, BillingOpenChannelAnswer o) {
getOrCreatePeer(macAddress.toLowerCase()).setBillingOpenChannelAnswer(o);
}
public void setLatestBillingCloseChannel(String macAddress, BillingCloseChannel o) {
getOrCreatePeer(macAddress.toLowerCase()).setBillingCloseChannel(o);
}
public void setLatestBillingCloseChannelAnswer(String macAddress, BillingCloseChannelAnswer o) {
getOrCreatePeer(macAddress.toLowerCase()).setBillingCloseChannelAnswer(o);
}
public PeerInformation getPeer(String address) {
address = address.toLowerCase();
if (peers.containsKey(address)) {
return peers.get(address);
}
return null;
}
}

View File

@ -363,9 +363,11 @@ public class Negotiator {
double bandwidth = 0.1; // megabyte per second;
int max_data_volume_megabytes = (int) (answer.getDuranceInMinutes() * bandwidth);
int max_iota_transferred = max_data_volume_megabytes * offer.getIotaPerMegabyte();
max_iota_transferred = 10;
String rootAddress = "JZWUMRUEYFJOCDDRZCNIIMDZSX9LWMITNMDIAIUJKUV9LVDLSICDABFYTTBZFGEBJOADDN9WZ9IJJJD9DXRJRR9TOW";
// send the most important message to the user
NegotiationFinalization finalization = new NegotiationFinalization(hotspotName, password,
"Address", max_iota_transferred, max_iota_transferred, "");
rootAddress, max_iota_transferred, max_iota_transferred, "<flashObj>");
PeerStore.getInstance().setLatestFinalization(otherMac, finalization);
String finalizationString = gson.toJson(finalization);

View File

@ -6,6 +6,8 @@ public class NegotiationFinalization {
private String hotspotName;
private String hotspotPassword;
private String depositAddressFlashChannel;
private String clientRefundAddress;
private String hotspotRefundAddress;
private int depositServerFlashChannelInIota;
private int depositClientFlashChannelInIota;
private String flashObject;
@ -27,4 +29,28 @@ public class NegotiationFinalization {
public String getHotspotPassword() {
return hotspotPassword;
}
public String getDepositAddressFlashChannel() {
return depositAddressFlashChannel;
}
public int getDepositServerFlashChannelInIota() {
return depositServerFlashChannelInIota;
}
public int getDepositClientFlashChannelInIota() {
return depositClientFlashChannelInIota;
}
public String getFlashObject() {
return flashObject;
}
public String getClientRefundAddress() {
return clientRefundAddress;
}
public String getHotspotRefundAddress() {
return hotspotRefundAddress;
}
}

View File

@ -60,6 +60,19 @@
android:clickable="false"
android:text="Flash channel" />
<CheckBox
android:id="@+id/channelFunded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:checked="false"
android:clickable="false"
android:text="Channel funded" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"