Compare commits

..

1 Commits

Author SHA1 Message Date
7de7632101 * init p2p-poll 2026-03-18 20:09:20 +01:00
11 changed files with 10295 additions and 39 deletions

View File

@@ -1,39 +1 @@
# P2P Poll App # P2P Poll App
There are various issues of Trust:
The possiblity to generate lots of users that do a lot of things (at a rather low cost)
The possibility to put out wrong data, maby not even contradicting but additional to existing data.
The possibility to do all kinds of shenenigans like spam other users with some requests
Due to low programming knowledge, the starting point of this proposal was to mirror how normal groups of people solve issues of trust to then automate and possibly improve the process. There are already some systems out there like Trust flow or random walk. As far as i understand it, the Flexible Trust Web also already does something like this, also maby RWOT and GNUweb but i didn't read into them too much since i discovered them rather late and want to look for feedback anyway. After all, a system with a clearer consensus might be preferable to some.
If random new people should be able to use the system as equals to previous users, but the system never has real identities as an input, then there is no way to fully prevent the creation of new users to manipulate or sabotage the poll. But it can be assumed, that your friends are rather trustworthy and most likely also their friends and so on. And if someone makes huge ammounts or just one second account, they will probably only have the creator or maby some other people as friends, and even they might already be less socially connected than a normal user.
So the social distance to another user should be evaluated to see, whether you should count their vote.
This is evaluated for and by every user individually, based on the information they were sent. The ammount of contacts you won't count are displayed to you, such that you get a hint at how many people you are missing but also how many people are not counting you. This encourages people to try to prove others/vise versa and make social connections to officially tie the network closer together such that the voting system works and confirms itself. It would be great, if there was some chat attached to the poll. If people want to prove their (or others) trusworhiness within this system, they are then also encouraged to have productive discussions, probably about the matter of the poll.
Everyone in a poll with you is a "contact" of yours.
"users" can have "friends".
You can also manually mark users as suspicious or trustworthy or normal again.
The system for evaluating the trustworthyness of users is somehow a mix between the concepts "weighted path score" and "trust flow" with 5 steps.
That means for 5 steps starting with you, all friends and trusted people of people looked at in this step get some trust from the people we look at: 0.8 * The trust of the looked at person (if trusted) + 0.8 * The trust of the looked at person / friends the looked at person has (if friend). Then the trust of the person that received trust may maximally be 100. The Trust you have to yourself is 100.
You can also mark someone as trustworthy or untrustworthy. That is then also sent around to everyone if you want(should be the standard, but maby a user wants to just see how the trustworthyness will look like after the change).
If you receive such an information, you can make the following calculations immidiately and after every assesment of everyones trustworthyness:
If the accused is less trustworthy then the accusing person, decrease the accused trustworthyness to 0 and the accused friends and trustees trustworthyness by the trustworthyness of the accusing person.
If the trustworhyness of the accusing person is less than the trustworthyness of the accused, then reduce the trustworthyness of the accusing person to 0 and the accusing persons friends and trustees by the trustworthyness of the accused * 0,2.
If you mark someone as trustworthy:
The Trust flowing to the trusted person from you will also be 0.8 of your trust.
Maby this should also be the effect of beeing "friends" since "trust" might be something you could more intuitively casually deal out after a short chat. If that change were to occur, then the effect would have to be switched around.
All contacts can maximally have the Trust 100.
Future matters:
If there can be any discrepancy of sent information, depending on what sender you trust most, you will mark one of the senders as untrustworthy and neglect all future information from this user. Since everything can be signed and such, that shouldnˋt be an issue tho, but if it was, the ammount of "useless" messages to already informed people might have to increase to validate received data.
A system to showcase the social connections in a 2D - format would be neat.
(most likely something like this exists already)
Obviously the user would also have to see other context like the total of all votes (trusted or not)
Anonymous polls:
A system of individually assigned trust poses a challenge for a system where you can decide not to trust some voters.
If there is no other option some compromises might be makable, such as:
-Your Friends can know what you voted for
-The Person initiating a poll just decides on the validity of participants according to an own judgement of trust at the moment of poll-creation
-A System with clear Consensus of who to trust

24
p2p-poll/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example

75
p2p-poll/README.md Normal file
View File

@@ -0,0 +1,75 @@
# Nuxt Minimal Starter
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
## Setup
Make sure to install dependencies:
```bash
# npm
npm install
# pnpm
pnpm install
# yarn
yarn install
# bun
bun install
```
## Development Server
Start the development server on `http://localhost:3000`:
```bash
# npm
npm run dev
# pnpm
pnpm dev
# yarn
yarn dev
# bun
bun run dev
```
## Production
Build the application for production:
```bash
# npm
npm run build
# pnpm
pnpm build
# yarn
yarn build
# bun
bun run build
```
Locally preview production build:
```bash
# npm
npm run preview
# pnpm
pnpm preview
# yarn
yarn preview
# bun
bun run preview
```
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

152
p2p-poll/app/app.vue Normal file
View File

@@ -0,0 +1,152 @@
<style>
/* Basic styling to make it look clean */
body {
font-family: system-ui, -apple-system, sans-serif;
background-color: #f4f4f9;
color: #333;
margin: 0;
display: flex;
justify-content: center;
padding: 2rem;
}
.poll-container {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
width: 100%;
max-width: 500px;
}
header {
margin-bottom: 2rem;
text-align: center;
}
h1 { margin: 0 0 0.5rem 0; }
.status {
font-size: 0.85rem;
color: #666;
}
.status .connected { color: #10b981; font-weight: bold; }
.add-option-form {
display: flex;
gap: 0.5rem;
margin-bottom: 2rem;
}
input {
flex-grow: 1;
padding: 0.75rem;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 1rem;
}
button {
background: #3b82f6;
color: white;
border: none;
padding: 0.75rem 1rem;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
transition: background 0.2s;
}
button:hover { background: #2563eb; }
.poll-list {
list-style: none;
padding: 0;
margin: 0;
}
.poll-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
margin-bottom: 0.5rem;
}
.option-name { font-weight: 500; }
.vote-section { display: flex; align-items: center; gap: 1rem; }
.vote-count { font-size: 0.9rem; color: #475569; }
.vote-btn { padding: 0.4rem 0.8rem; background: #10b981; }
.vote-btn:hover { background: #059669; }
.empty-state { text-align: center; color: #94a3b8; font-style: italic; }
</style>
<template>
<div class="poll-container">
<ClientOnly>
<header>
<h1>P2P Polling App 🗳</h1>
<div class="status">
<span :class="{ 'connected': isConnected }">
{{ isConnected ? 'Synced' : 'Connecting...' }}
</span>
<span> | Peers online: {{ connectedPeers }}</span>
</div>
</header>
<main>
<form @submit.prevent="handleAddNewOption" class="add-option-form">
<input
v-model="newOption"
type="text"
placeholder="Enter a new poll option..."
required
/>
<button type="submit">Add Option</button>
</form>
<div v-if="Object.keys(pollData).length === 0" class="empty-state">
No options yet. Be the first to add one!
</div>
<ul v-else class="poll-list">
<li v-for="(votes, optionName) in pollData" :key="optionName" class="poll-item">
<span class="option-name">{{ optionName }}</span>
<div class="vote-section">
<span class="vote-count">{{ votes }} {{ votes === 1 ? 'vote' : 'votes' }}</span>
<button @click="vote(String(optionName))" class="vote-btn">+1</button>
</div>
</li>
</ul>
</main>
<template #fallback>
<div class="empty-state">Loading P2P Node...</div>
</template>
</ClientOnly>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
// Manually define 'global' for the browser
if (process.client) {
(window as any).global = window;
}
import { usePoll } from '../composables/usePoll';
// Because WebRTC requires the browser environment (window/navigator),
// we ensure our composable only runs on the client side in Nuxt.
const newOption = ref('');
// Destructure our P2P logic
const { pollData, isConnected, connectedPeers, addOption, vote } = usePoll();
const handleAddNewOption = () => {
addOption(newOption.value);
newOption.value = ''; // Reset input
};
</script>

View File

@@ -0,0 +1,81 @@
// composables/usePoll.ts
import { ref, onMounted, onUnmounted } from 'vue';
import * as Y from 'yjs';
export const usePoll = () => {
// Reactive Vue state to drive the UI
const pollData = ref<Record<string, number>>({});
const isConnected = ref(false);
const connectedPeers = ref(1); // 1 = just you initially
let ydoc: Y.Doc;
let provider: any;
let yMap: Y.Map<number>;
onMounted(async () => {
// 1. Initialize the Yjs document
ydoc = new Y.Doc();
// 2. Connect via WebRTC.
// 'nuxt-p2p-poll-demo-room' is the shared room name.
// Anyone using this exact string will sync together.
const { WebrtcProvider } = await import('y-webrtc');
provider = new WebrtcProvider('nuxt-p2p-poll-demo-room', ydoc);
// Track connection status
provider.on('synced', (arg: {synced: boolean}) => {
isConnected.value = arg.synced;
});
provider.on('peers', (data: any) => {
// data.webrtcPeers contains the connected peer IDs
connectedPeers.value = data.webrtcPeers.length + 1; // +1 for self
});
// 3. Define our shared state structure. We'll use a Map
// where the Key is the Poll Option (string) and Value is the Vote Count (number)
yMap = ydoc.getMap<number>('shared-poll');
// 4. Listen for changes from other peers and update our Vue reactive state
yMap.observe(() => {
pollData.value = yMap.toJSON();
});
// Initial load in case data already exists in the room
pollData.value = yMap.toJSON();
});
onUnmounted(() => {
// Clean up when the component is destroyed
if (provider) {
provider.disconnect();
}
if (ydoc) {
ydoc.destroy();
}
});
// Action: Add a new option to the poll
const addOption = (optionName: string) => {
const trimmedName = optionName.trim();
if (trimmedName && !yMap.has(trimmedName)) {
yMap.set(trimmedName, 0); // Initialize with 0 votes
}
};
// Action: Vote for an existing option
const vote = (optionName: string) => {
if (yMap.has(optionName)) {
const currentVotes = yMap.get(optionName) || 0;
yMap.set(optionName, currentVotes + 1);
}
};
return {
pollData,
isConnected,
connectedPeers,
addOption,
vote
};
};

11
p2p-poll/nuxt.config.ts Normal file
View File

@@ -0,0 +1,11 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
ssr: false,
vite: {
optimizeDeps: {
include: ['yjs', 'y-webrtc']
}
}
})

9912
p2p-poll/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
p2p-poll/package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "p2p-poll",
"type": "module",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"nuxt": "^4.1.3",
"vue": "^3.5.30",
"vue-router": "^5.0.3",
"y-webrtc": "^10.3.0",
"yjs": "^13.6.30"
}
}

BIN
p2p-poll/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1,2 @@
User-Agent: *
Disallow:

18
p2p-poll/tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"files": [],
"references": [
{
"path": "./.nuxt/tsconfig.app.json"
},
{
"path": "./.nuxt/tsconfig.server.json"
},
{
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
}
]
}