croc icon indicating copy to clipboard operation
croc copied to clipboard

Developing Apis to interact with Croc programmatically

Open EggsyOnCode opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe.

I was thinking of developing a website where ppl could drop in their files and retrieve them from the other end using croc. This situation comes in handy for the non technical folk who might not have croc installed as a cli util. That's where a web interface would come in handy.

Describe the solution you'd like To have croc sdk installed on the web server to interface with Croc functionality programmatically.

Describe alternatives you've considered None

Additional context None

EggsyOnCode avatar Feb 25 '24 23:02 EggsyOnCode

+1

My idea was to implement a plugin for a document management systems which contacts a croc relay to retrieve a file. Is there any documentation on how to talk to the relay?

SeedDMS avatar Apr 04 '24 11:04 SeedDMS

check cli.go to see how to use croc as an API: https://github.com/schollz/croc/blob/v9.6.15/src/cli/cli.go

schollz avatar Apr 06 '24 16:04 schollz

I was actually hoping for something the describes the protocol between client and relay, because I do not intend to use go but php to access the relay.

SeedDMS avatar Apr 08 '24 14:04 SeedDMS

you don't need to use Go. but that file describes the protocol in Go code

schollz avatar May 20 '24 13:05 schollz

It's still difficult to collect the parts together. Most of the protocol code appears to be in https://github.com/schollz/croc/blob/v9.6.15/src/croc/croc.go but I'm still missing the overall picture for receiving a file which has been send to a relay.

SeedDMS avatar May 23 '24 11:05 SeedDMS

I'm still missing the overall picture for receiving a file which has been send to a relay

here's the overall picture on how receiving a file with croc works:

  1. when you run croc receive <code>, croc starts by connecting to the relay server using the provided code.

  2. the relay server helps both the sender and receiver establish a connection, even if they are behind different network setups like nat or firewalls.

  3. once connected through the relay, croc sets up an encrypted channel using the same code to ensure the transfer is secure.

  4. croc attempts to switch to a direct peer-to-peer connection for better speed. if that's not possible, it continues using the relay. the file transfer begins, and you will see progress updates in your terminal.

  5. after the file is fully transferred, croc verifies the integrity of the received file to make sure everything is correct.

you can find the main logic for handling this process in croc.go, but it also interacts with several other parts of the codebase for encryption, connection handling, and progress reporting.

schollz avatar May 23 '24 13:05 schollz

Stale issue message

github-actions[bot] avatar Jul 27 '24 12:07 github-actions[bot]