Skip to content

Commit

Permalink
update README to fix bad code in client example
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bland committed Aug 26, 2022
1 parent 2495dd6 commit 9224a32
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
112 changes: 58 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,82 +136,86 @@ Minitor will print the address of the onion service to the console but if you mi
## Connecting to an Onion Service

```
#include "stdio.h"
#include <string.h>
#include <minitor.h>
#include <minitor_client.h>
const char* REQUEST =
"GET / HTTP/1.0\r\n"
"Host: 127.0.0.1\r\n"
"User-Agent: esp-idf/1.0 esp3266\r\n"
"Content-Type: text/plain\r\n"
"\r\n\r\n";
int i;
OnionClient* client;
int stream;
int ret;
char read_buf[512];
if ( d_minitor_INIT() < 0 )
void main()
{
printf( "Failed to init" );
const char* REQUEST =
"GET / HTTP/1.0\r\n"
"Host: 127.0.0.1\r\n"
"User-Agent: esp-idf/1.0 esp3266\r\n"
"Content-Type: text/plain\r\n"
"\r\n\r\n";
int i;
void* client;
int stream;
int ret;
char read_buf[512];
while ( 1 )
if ( d_minitor_INIT() < 0 )
{
printf( "Failed to init" );
while ( 1 )
{
}
}
}
// create a rendezvous circuit with the service
client = px_create_onion_client( "duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion" );
client = px_create_onion_client( "duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion" );
if ( client == NULL )
{
while ( 1 )
if ( client == NULL )
{
printf( "Failed to create client\n" );
sleep( 1 );
while ( 1 )
{
printf( "Failed to create client\n" );
sleep( 1 );
}
}
}
// create a stream on the circuit
stream = d_connect_onion_client( client, 80 )
// create a stream on the circuit
stream = d_connect_onion_client( client, 80 );
if ( stream < 0 )
{
while ( 1 )
if ( stream < 0 )
{
printf( "Failed to connect client\n" );
sleep( 1 );
while ( 1 )
{
printf( "Failed to connect client\n" );
sleep( 1 );
}
}
}
// write to the http request to the stream
if ( d_write_onion_client( client, stream, REQUEST, strlen( REQUEST ) ) != strlen( REQUEST ) )
{
while ( 1 )
// write to the http request to the stream
if ( d_write_onion_client( client, stream, REQUEST, strlen( REQUEST ) ) != strlen( REQUEST ) )
{
printf( "Failed to write client\n" );
sleep( 1 );
while ( 1 )
{
printf( "Failed to write client\n" );
sleep( 1 );
}
}
}
do
{
ret = d_read_onion_client( client, stream, read_buf, sizeof( read_buf ) );
if ( ret < 0 )
do
{
printf( "Failed to read on stream\n" );
break;
}
ret = d_read_onion_client( client, stream, read_buf, sizeof( read_buf ) );
printf( "ret %d\n", ret );
if ( ret < 0 )
{
printf( "Failed to read on stream\n" );
break;
}
for ( i = 0; i < ret; i++ )
{
printf( "read_buf[%d] %c\n", i, read_buf[i] );
}
} while ( ret == sizeof( read_buf ) );
printf( "ret %d\n", ret );
for ( i = 0; i < ret; i++ )
{
printf( "read_buf[%d] %c\n", i, read_buf[i] );
}
} while ( ret == sizeof( read_buf ) );
}
```

This example connects to the duckduckgo hidden service and prints out each byte of the homepage.
Expand Down
1 change: 1 addition & 0 deletions examples/client_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <minitor.h>
#include <minitor_client.h>

void main()
{
const char* REQUEST =
Expand Down

0 comments on commit 9224a32

Please sign in to comment.