Browse Source

proxy: Provide a place to store desired proxyshare difficulty on a per-username basis, and copy it to SSM connections when authorising them

Luke Dashjr 11 years ago
parent
commit
626a6f5a19
3 changed files with 10 additions and 2 deletions
  1. 1 0
      driver-proxy.c
  2. 1 0
      driver-proxy.h
  3. 8 2
      driver-stratum.c

+ 1 - 0
driver-proxy.c

@@ -110,6 +110,7 @@ struct proxy_client *proxy_find_or_create_client(const char *username)
 		*client = (struct proxy_client){
 		*client = (struct proxy_client){
 			.username = user,
 			.username = user,
 			.cgpu = cgpu,
 			.cgpu = cgpu,
+			.desired_share_pdiff = opt_scrypt ? (1./0x10000) : 1.,
 		};
 		};
 		
 		
 		b = HASH_COUNT(proxy_clients);
 		b = HASH_COUNT(proxy_clients);

+ 1 - 0
driver-proxy.h

@@ -10,6 +10,7 @@ struct proxy_client {
 	struct cgpu_info *cgpu;
 	struct cgpu_info *cgpu;
 	struct work *work;
 	struct work *work;
 	struct timeval tv_hashes_done;
 	struct timeval tv_hashes_done;
+	float desired_share_pdiff;
 	
 	
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 };
 };

+ 8 - 2
driver-stratum.c

@@ -65,6 +65,7 @@ struct stratumsrv_conn {
 	bool hashes_done_ext;
 	bool hashes_done_ext;
 	float current_share_pdiff;
 	float current_share_pdiff;
 	float desired_share_pdiff;
 	float desired_share_pdiff;
+	bool have_authorised_user;
 	
 	
 	struct stratumsrv_conn *next;
 	struct stratumsrv_conn *next;
 };
 };
@@ -375,13 +376,18 @@ void stratumsrv_mining_subscribe(struct bufferevent * const bev, json_t * const
 }
 }
 
 
 static
 static
-void stratumsrv_mining_authorize(struct bufferevent *bev, json_t *params, const char *idstr, uint32_t *xnonce1_p)
+void stratumsrv_mining_authorize(struct bufferevent * const bev, json_t * const params, const char * const idstr, struct stratumsrv_conn * const conn)
 {
 {
 	struct proxy_client * const client = stratumsrv_find_or_create_client(__json_array_string(params, 0));
 	struct proxy_client * const client = stratumsrv_find_or_create_client(__json_array_string(params, 0));
 	
 	
 	if (unlikely(!client))
 	if (unlikely(!client))
 		return_stratumsrv_failure(20, "Failed creating new cgpu");
 		return_stratumsrv_failure(20, "Failed creating new cgpu");
 	
 	
+	if ((!conn->have_authorised_user) || client->desired_share_pdiff < conn->desired_share_pdiff)
+		conn->desired_share_pdiff = client->desired_share_pdiff;
+	
+	conn->have_authorised_user = true;
+	
 	_stratumsrv_success(bev, idstr);
 	_stratumsrv_success(bev, idstr);
 }
 }
 
 
@@ -525,7 +531,7 @@ errout:
 		stratumsrv_mining_hashes_done(bev, params, idstr, conn);
 		stratumsrv_mining_hashes_done(bev, params, idstr, conn);
 	else
 	else
 	if (!strcasecmp(method, "mining.authorize"))
 	if (!strcasecmp(method, "mining.authorize"))
-		stratumsrv_mining_authorize(bev, params, idstr, &conn->xnonce1_le);
+		stratumsrv_mining_authorize(bev, params, idstr, conn);
 	else
 	else
 	if (!strcasecmp(method, "mining.subscribe"))
 	if (!strcasecmp(method, "mining.subscribe"))
 		stratumsrv_mining_subscribe(bev, params, idstr, conn);
 		stratumsrv_mining_subscribe(bev, params, idstr, conn);