Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e226127

Browse files
[skip changelog] Update client_example with proxy
1 parent d92816b commit e226127

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

‎client_example/README.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Client example
2+
3+
This a client that simulates a gRPC consumer. We're using this for the time being to test the interaction with the gRPC
4+
interface, hopefully in the future we'll have proper integration tests.
5+
6+
To use it run `arduino-cli daemon` and then `client_example`.
7+
8+
To test the proxy settings first run:
9+
10+
```
11+
docker run --name squid -d --restart=always \
12+
--publish 3128:3128 \
13+
--volume /path/to/squid.conf:/etc/squid/squid.conf \
14+
--volume /srv/docker/squid/cache:/var/spool/squid \
15+
sameersbn/squid:3.5.27-2
16+
```
17+
18+
The `squid.conf` file to use is in this directory so change the volume path to that.
19+
20+
To verify that requests are passing through the local proxy run:
21+
22+
```
23+
docker exec -it squid tail -f /var/log/squid/access.log
24+
```
25+
26+
If it works you should see logs similar to this:
27+
28+
```
29+
1612176447.893 400234 172.17.0.1 TCP_TUNNEL/200 116430 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
30+
1612176448.197 400245 172.17.0.1 TCP_TUNNEL/200 1621708 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
31+
1612176448.946 400256 172.17.0.1 TCP_TUNNEL/200 354882 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
32+
```

‎client_example/main.go‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func main() {
9090
log.Println("calling GetValue(foo)")
9191
callGetValue(settingsClient)
9292

93+
// List all the settings.
94+
log.Println("calling GetAll()")
95+
callGetAll(settingsClient)
96+
9397
// Write settings to file.
9498
log.Println("calling Write()")
9599
callWrite(settingsClient)
@@ -100,11 +104,19 @@ func main() {
100104
log.Println("calling Init")
101105
instance := initInstance(client)
102106

107+
// We set up the proxy and then run the update to verify that the proxy settings are currently used
108+
log.Println("calling setProxy")
109+
callSetProxy(settingsClient)
110+
103111
// With a brand new instance, the first operation should always be updating
104112
// the index.
105113
log.Println("calling UpdateIndex")
106114
callUpdateIndex(client, instance)
107115

116+
// And we run update again
117+
log.Println("calling UpdateIndex")
118+
callUpdateIndex(client, instance)
119+
108120
// Let's search for a platform (also known as 'core') called 'samd'.
109121
log.Println("calling PlatformSearch(samd)")
110122
callPlatformSearch(client, instance)
@@ -220,6 +232,31 @@ func callSetValue(client settings.SettingsClient) {
220232
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
221233
})
222234

235+
if err != nil {
236+
log.Fatalf("Error setting settings value: %s", err)
237+
238+
}
239+
}
240+
241+
func callSetProxy(client settings.SettingsClient) {
242+
_, err := client.SetValue(context.Background(),
243+
&settings.Value{
244+
Key: "network.proxy",
245+
JsonData: `"http://localhost:3128"`,
246+
})
247+
248+
if err != nil {
249+
log.Fatalf("Error setting settings value: %s", err)
250+
}
251+
}
252+
253+
func callUnsetProxy(client settings.SettingsClient) {
254+
_, err := client.SetValue(context.Background(),
255+
&settings.Value{
256+
Key: "network.proxy",
257+
JsonData: `""`,
258+
})
259+
223260
if err != nil {
224261
log.Fatalf("Error setting settings value: %s", err)
225262
}

‎client_example/squid.conf‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
http_port 3128
2+
3+
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
4+
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
5+
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
6+
acl localnet src fc00::/7 # RFC 4193 local private network range
7+
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
8+
9+
acl SSL_ports port 443
10+
11+
acl Safe_ports port 80 # http
12+
acl Safe_ports port 21 # ftp
13+
acl Safe_ports port 443 # https
14+
acl Safe_ports port 70 # gopher
15+
acl Safe_ports port 210 # wais
16+
acl Safe_ports port 280 # http-mgmt
17+
acl Safe_ports port 488 # gss-http
18+
acl Safe_ports port 591 # filemaker
19+
acl Safe_ports port 777 # multiling http
20+
acl Safe_ports port 1025-65535 # unregistered ports
21+
22+
acl CONNECT method CONNECT
23+
24+
http_access deny !Safe_ports
25+
http_access deny CONNECT !SSL_ports
26+
http_access allow localhost manager
27+
http_access deny manager
28+
29+
#
30+
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
31+
#
32+
33+
http_access allow localnet
34+
http_access allow localhost
35+
http_access allow all
36+
37+
coredump_dir /squid/var/cache/squid
38+
39+
refresh_pattern ^ftp: 1440 20% 10080
40+
refresh_pattern ^gopher: 1440 0% 1440
41+
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
42+
refresh_pattern . 0 20% 4320

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /