Mobile Application DevelopmentUnit 57 min read
Mobile Agents & P2P: Architectures, Workflows & Real-World Apps
Unit 5 of Mobile Application Development explores mobile agent systems (autonomous code that migrates between devices) and peer-to-peer (P2P) architectures (decentralized networks like BitTorrent or WhatsApp calls), comparing them to client-server models. Covers workflows, security challenges, and Nepalese/global case
Core Concepts: Mobile Agents vs. P2P
What Are Mobile Agents?
Mobile agents are autonomous programs that:
- Execute on behalf of users (e.g., fetching data, negotiating deals).
- Can migrate between devices (e.g., from a user’s phone to a server).
- Operate asynchronously (no constant connection needed).
classDiagram
class MobileAgent {
+execute()
+migrate(targetDevice)
+state: {code, data, executionPoint}
}
class Device {
+hostAgent(agent)
+executeLocally(agent)
}
MobileAgent --> Device : "migrates to"
Device --> MobileAgent : "executes"Example Workflow:
- A user’s phone sends an agent to a Daraz server to check stock.
- The agent migrates to a warehouse’s IoT device to verify inventory in real-time.
- Results return to the user’s phone without manual polling.
In the Real World
Khalti’s P2P Payments
- Uses P2P architecture to route transactions directly between users (no central bank server for every transfer).
- How: When you send money via Khalti, your phone connects peer-to-peer with the recipient’s phone (via Khalti’s relay nodes) to settle the transaction in seconds.
Pathao’s Driver Matching
- Uses mobile agents to dynamically assign rides:
- Your phone sends an agent to Pathao’s cloud to find the nearest available driver.
- The agent migrates to the driver’s phone to negotiate fare/route before confirming.
- Uses mobile agents to dynamically assign rides:
NTC’s Network Monitoring
- NTC’s P2P-based fault detection lets base stations share traffic data directly (reducing latency vs. client-server polling).
Peer-to-Peer (P2P) Architectures
P2P networks eliminate centralized servers by letting peers (devices) act as both clients and servers.
How P2P Works: BitTorrent Example
flowchart TD
A["Peer 1 (Downloads File)"] -->|"requests chunks"| B["Peer 2 (Has Chunks)"]
B -->|"sends chunks"| A
A -->|"requests chunks"| C["Peer 3 (Has Chunks)"]
C -->|"sends chunks"| A
A -->|"uploads chunks"| D["Peer 4 (Downloads File)"]Key Terms:
- Superpeers: High-capacity nodes (e.g., WhatsApp’s relay servers).
- Torrent: A file split into chunks shared across peers.
- DHT (Distributed Hash Table): Maps data to peers (e.g., IPFS uses this).
Mobile Agent vs. P2P: Comparison Table
| Feature | Mobile Agents | P2P Networks |
|---|---|---|
| Definition | Code that moves between devices | Decentralized network of peers |
| Use Case | Autonomous tasks (e.g., negotiations) | Data sharing (e.g., file downloads) |
| Migration | Agents move to execute tasks | Data moves between peers |
| Example (Nepal) | Khalti’s payment agents | Daraz’s P2P order routing |
| Security Risk | Malicious agents on untrusted devices | Sybil attacks (fake peers) |
| Latency | Low (agent executes locally) | Variable (depends on peer availability) |
Worked Example: Mobile Agent for Loan Approval
Scenario: A bank (e.g., NMB) uses mobile agents to approve loans on users’ phones.
Agent Creation:
- User submits loan request → bank creates an agent with:
loanAmount = 500,000creditScore = 720migrationTarget = "userPhone"
- User submits loan request → bank creates an agent with:
Agent Migration:
sequenceDiagram Bank->>+Agent: create() Agent->>UserPhone: migrate() UserPhone->>Agent: execute()
Execution on User’s Phone:
- Agent checks local data (salary slips, bank statements) without uploading to cloud.
- If approved, agent migrates back to bank with signed contract.
State After Each Step:
graph LR
A["Bank: Agent created\n(loanAmount=500k)"]
B["UserPhone: Agent arrives\n(creditScore=720)"]
C["Bank: Agent returns\n(approval=YES)"]
A --> B --> CCode Snippet (Pseudocode):
class LoanAgent:
def __init__(self, amount, score):
self.amount = amount
self.score = score
self.approved = False
def migrate(self, device):
print(f"Agent migrated to {device}")
if self.score >= 700:
self.approved = True
return self
def execute(self):
return {"status": "approved" if self.approved else "rejected"}
Trace Table:
| Step | Device | Agent State | Output |
|---|---|---|---|
| 1 | Bank | LoanAgent(500k, 720) |
Agent created |
| 2 | UserPhone | LoanAgent(500k, 720, approved=True) |
Executes locally |
| 3 | Bank | LoanAgent(500k, 720, approved=True) |
Returns approval |
Security Challenges
For Mobile Agents:
- Malicious Hosts: An agent could be tampered with on an untrusted device (e.g., a hacked Daraz warehouse server).
- Cloning: Agents can be duplicated to bypass authentication.
- Solution: Use digital signatures and sandboxing (isolated execution environments).
For P2P Networks:
- Sybil Attacks: Fake peers flood the network (e.g., in NEPSE’s P2P trading, bots could manipulate stock prices).
- Free-Riding: Peers consume resources without sharing (e.g., downloading from BitTorrent without uploading).
- Solution: Reputation systems (e.g., WhatsApp’s peer ratings) and economic incentives (e.g., faster downloads for uploaders).
Advantages and Disadvantages
Mobile Agents
| Pros | Cons |
|---|---|
| Offline capability (agents work without constant connection) | Complexity (hard to debug) |
| Reduced network load (data processed locally) | Security risks (malicious hosts) |
| Autonomy (no manual intervention) | Limited adoption (most apps use REST APIs) |
P2P Networks
| Pros | Cons |
|---|---|
| Scalability (no single point of failure) | Security vulnerabilities (Sybil attacks) |
| Cost-effective (no central servers) | Latency (depends on peer availability) |
| Resilience (works even if some peers fail) | Legal issues (e.g., copyright in file-sharing) |
Exam Tip
Define Clearly:
- Mobile agents = code that moves; P2P = decentralized network.
- Example: "A mobile agent is like a courier that carries documents (data) between offices (devices)."
Compare with Client-Server:
- Client-server: Centralized control (e.g., Ncell’s billing server).
- P2P: Distributed control (e.g., Pathao drivers acting as peers).
Real-World Links:
- Khalti = P2P payments.
- Daraz’s order routing = hybrid (P2P for peer-to-peer delivery + agents for tracking).
- NTC’s network = P2P monitoring to reduce latency.
Diagrams Are Key:
- Draw agent migration paths (sequence diagrams).
- Show P2P data flow (e.g., BitTorrent chunks moving between peers).
Security Trade-offs:
- Mobile agents: Trust the device.
- P2P: Trust the network (but verify peers).
Visual Summary:
mindmap
root((Mobile Agents & P2P))
Mobile Agents
Definition: Autonomous code
Workflow: Migration + Execution
Example: Khalti payment agents
Security: Sandboxing
P2P Networks
Definition: Decentralized peers
Example: BitTorrent, WhatsApp calls
Security: Reputation systems
Types: Pure P2P vs. Hybrid
Comparison
Centralization: Agents = Code moves; P2P = Data moves
Use Cases: Agents = Tasks; P2P = SharingBased on the TU BIT syllabus for Mobile Application Development, unit 5.
Discussion
Loading…