Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust server #3

Merged
merged 34 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d3199f7
init
p-shahi Mar 21, 2023
f1ce94a
add kad
p-shahi Mar 21, 2023
f62e4a5
add kad behaviour
p-shahi Mar 21, 2023
d806f67
feat: add ability to connect to multiaddr
2color Mar 21, 2023
093ddee
Update rust-server/Cargo.toml
2color Mar 21, 2023
ada67ba
add ping and keep alive
p-shahi Mar 21, 2023
159836b
ValidationMode permissive
p-shahi Mar 21, 2023
98aa57e
refactored to use dialProtocol + added ping
maschad Mar 22, 2023
6cadfaf
disable creating topic
p-shahi Mar 22, 2023
59f4c35
Apply suggestions from code review
2color Mar 22, 2023
bb43fcd
chore: update packages
2color Mar 22, 2023
592cb52
log full p2p address and fixes from pair with max
2color Mar 22, 2023
df59c56
.
p-shahi Mar 22, 2023
d1af50e
fix merge conflicts
p-shahi Mar 22, 2023
2c6f8f0
enable ping and increase idle timeout
2color Mar 22, 2023
03dcb3d
updates to frontend and js-libp2p
2color Mar 22, 2023
f9995a8
Update rust-server/Cargo.toml
p-shahi Mar 22, 2023
446db90
add dockerfile
2color Mar 22, 2023
390d557
deploy to fly
2color Mar 22, 2023
d96f54c
add fly config
2color Mar 22, 2023
680c8bd
listen and bind on port 5888
2color Mar 22, 2023
38bb908
enable manual deployment
2color Mar 22, 2023
bf1be77
enable logging
2color Mar 22, 2023
1531929
integrated explicit peer adding for gossipsub + added recurring messa…
maschad Mar 22, 2023
6f251c9
remove fly from pipeline
2color Mar 23, 2023
074b376
publish at even intervals
p-shahi Mar 24, 2023
0780b58
fix toml
p-shahi Mar 24, 2023
a7a0384
add message id function
p-shahi Mar 24, 2023
f40128c
forcefully add mesh peers to subscribers in js-gossipsub
maschad Mar 24, 2023
a8c18c8
reenable webtransport
p-shahi Mar 27, 2023
1faaaa5
revert custom js-libp2p-gossipsub branch
p-shahi Mar 27, 2023
4756648
Fix missing SUBSCRIBE and refactor
mxinden Mar 29, 2023
357f08e
Merge pull request #6 from mxinden/rust-server
p-shahi Mar 29, 2023
a40fa93
Merge branch 'main' into rust-server
p-shahi Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/frontend/src/lib/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ export const connectToMultiaddrs =
return conns
}

// Attempt to connect to an array of multiaddrs
export const connectToMultiaddr =
(libp2p: Libp2p) => async (multiaddr: Multiaddr) => {
console.log(`dialling: ${multiaddr.toString()}`)
try {
const conn = await libp2p.dial(multiaddr)
console.info('connected to', conn.remotePeer, 'on', conn.remoteAddr)
return conn
} catch (e) {
console.error(e)
throw e
}
}

/**
* Returns a filtered list of public multiaddrs of a specific protocol
*
Expand Down
56 changes: 56 additions & 0 deletions packages/frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useCallback, useState } from 'react'
import { useInterval } from 'usehooks-ts'

import {
connectToMultiaddr,
connectToMultiaddrs,
filterPublicMultiaddrs,
getPeerMultiaddrs,
Expand All @@ -23,6 +24,7 @@ export default function Home() {
const { libp2p } = useLibp2pContext()
const [isConnected, setIsConnected] = useState(false)
const [peerID, setPeerID] = useState(DEFAULT_APP_PEER)
const [maddr, setMultiaddr] = useState('')
const [peers, setPeers] = useState<PeerId[]>([])
const [connections, setConnections] = useState<Connection[]>([])
const [latency, setLatency] = useState<number>()
Expand Down Expand Up @@ -131,6 +133,32 @@ export default function Home() {
[libp2p, multiaddrs, peerID],
)

const handleConnectToMultiaddr = useCallback(
async (e: React.MouseEvent<HTMLButtonElement>) => {
if (!maddr) {
return
}

try {
const connection = await connectToMultiaddr(libp2p)(multiaddr(maddr))
console.log('connection: ', connection)
return connection
} catch (e) {
console.error(e)
}
},
[libp2p, maddr],
)

// handleConnectToMultiaddr

const handleMultiaddrChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
setMultiaddr(e.target.value)
},
[setMultiaddr],
)

const handlePeerIdChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
setPeerID(e.target.value)
Expand Down Expand Up @@ -193,6 +221,7 @@ export default function Home() {
Get Multiaddrs
</button>
</div>

<div>
{multiaddrs && multiaddrs.length > 0 ? (
<>
Expand All @@ -217,6 +246,33 @@ export default function Home() {
</>
) : null}
</div>
<div className="my-6 w-1/2">
<label
htmlFor="peer-id"
className="block text-sm font-medium leading-6 text-gray-900"
>
multiaddr to connect to
</label>
<div className="mt-2">
<input
value={maddr}
type="text"
name="peer-id"
id="peer-id"
className="block w-full rounded-md border-0 py-1.5 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
placeholder="12D3Koo..."
aria-describedby="multiaddr-id-description"
onChange={handleMultiaddrChange}
/>
</div>
<button
type="button"
className="rounded-md bg-indigo-600 my-2 py-2 px-3 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
onClick={handleConnectToMultiaddr}
>
Connect to multiaddr
</button>
</div>
<p className="my-4 inline-flex items-center text-xl">
Connected:{' '}
{isConnected ? (
Expand Down
1 change: 1 addition & 0 deletions rust-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Loading